MessageHandler.c 781 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117
  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 int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char :4; //bit 4~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // Save configuration
  356. //=========================================
  357. int runShellCmd(const char*cmd)
  358. {
  359. int result = FAIL;
  360. char buf[256];
  361. FILE *fp;
  362. fp = popen(cmd, "r");
  363. if(fp != NULL)
  364. {
  365. while(fgets(buf, sizeof(buf), fp) != NULL)
  366. {
  367. DEBUG_INFO("%s\n", buf);
  368. }
  369. result = PASS;
  370. }
  371. pclose(fp);
  372. return result;
  373. }
  374. int StoreUsrConfigData(struct SysConfigData *UsrData)
  375. {
  376. int result = PASS;
  377. int fd,wrd;
  378. unsigned int i,Chk;
  379. unsigned char *ptr, *BufTmp;
  380. int MtdBlockSize = 0x300000;
  381. Chk=0;
  382. ptr=(unsigned char *)UsrData;
  383. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  384. {
  385. memset(BufTmp,0,MtdBlockSize);
  386. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  387. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  388. Chk+=*(BufTmp+i);
  389. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  390. // Output configuration to file.
  391. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  392. if (fd < 0)
  393. {
  394. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  395. free(BufTmp);
  396. return 0;
  397. }
  398. wrd=write(fd, BufTmp, MtdBlockSize);
  399. close(fd);
  400. if(wrd<MtdBlockSize)
  401. {
  402. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  407. DEBUG_INFO("Erase /dev/mtd10.\n");
  408. runShellCmd("flash_erase /dev/mtd10 0 0");
  409. DEBUG_INFO("Write /dev/mtd10.\n");
  410. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  411. DEBUG_INFO("Erase /dev/mtd11.\n");
  412. runShellCmd("flash_erase /dev/mtd11 0 0");
  413. DEBUG_INFO("Write /dev/mtd11.\n");
  414. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  415. system("rm -f /mnt/EvseConfig.bin");
  416. DEBUG_INFO("EvseConfig write to flash OK\n");
  417. }
  418. else
  419. {
  420. DEBUG_ERROR("alloc BlockSize NG\r\n");
  421. result = FAIL;
  422. }
  423. if(BufTmp!=NULL)
  424. free(BufTmp);
  425. return result;
  426. }
  427. //=========================================
  428. // Sqlite3 related function
  429. //=========================================
  430. static int selectSqlCount = 0;
  431. static int callback(void *data, int argc, char **argv, char **azColName){
  432. int i;
  433. //printf("%s: ", (const char*)data);
  434. selectSqlCount = argc;
  435. for(i = 0; i<argc; i++){
  436. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  437. }
  438. //printf("\n");
  439. return 0;
  440. }
  441. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  442. //int i;
  443. //printf("%s:\n", (const char*)data);
  444. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  445. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  446. return 0;
  447. }
  448. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  449. //printf("%s:\n", (const char*)data);
  450. //idTag
  451. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. //parentIdTag
  454. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  455. //expir_date
  456. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  457. //status
  458. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  459. //version
  460. if(columenCount > 5)
  461. idTagQuery.listVersionInt = atoi(columnValue[5]);
  462. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  463. return 0;
  464. }
  465. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  466. {
  467. // localversion = argv[5] ? atoi(argv[5]) : 0;
  468. // printf("localversion=%d\n", localversion);
  469. return 0;
  470. }
  471. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  472. {
  473. for (int i = 0; i < n_columns; i++)
  474. {
  475. DEBUG_INFO("%s\t", col_values[i]);
  476. }
  477. DEBUG_INFO("\n");
  478. return 0;
  479. }
  480. int OCPP_cleanLocalCache()
  481. {
  482. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  483. char *errMsg = 0;
  484. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  485. if (SQLITE_OK != rc)
  486. {
  487. DEBUG_INFO("SQL error: %s\n",errMsg);
  488. return FALSE;
  489. }
  490. return TRUE;
  491. }
  492. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  493. {
  494. int isSuccess = TRUE;
  495. int ret = 0;
  496. //const char* data = "Callback function called";
  497. char sql[300];
  498. char zErrMsg[200];
  499. memset(sql, 0, 300);
  500. memset(zErrMsg, 0, 200);
  501. 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);
  502. //* Execute SQL statement */
  503. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  504. if( ret != SQLITE_OK )
  505. {
  506. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  507. isSuccess = FALSE;
  508. }
  509. return isSuccess;
  510. }
  511. void OCPP_getIdTagFromLocalCache(char idTag[])
  512. {
  513. int rc = 0;
  514. char sql[100];
  515. char zErrMsg[100];
  516. memset(sql, 0, 100);
  517. memset(zErrMsg, 0, 100);
  518. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  519. memset(&idTagQuery, 0, sizeof(idTagQuery));
  520. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  521. /* Execute SQL statement */
  522. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  523. if( rc != SQLITE_OK )
  524. {
  525. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  526. }
  527. }
  528. void OCPP_getListVerion()
  529. {
  530. int rc = 0;
  531. // const char* data = "Callback function called";
  532. char sql[100];
  533. char zErrMsg[100];
  534. memset(sql, 0, 100);
  535. memset(zErrMsg, 0, 100);
  536. strcpy(sql, "select * from ocpp_auth_local order by idx");
  537. /* Execute SQL statement */
  538. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  539. if( rc != SQLITE_OK )
  540. {
  541. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  542. }
  543. }
  544. void OCPP_get_TableAuthlocalAllData(void)
  545. {
  546. int rc = 0;
  547. char sql[100];
  548. char zErrMsg[100];
  549. memset(sql, 0, 100);
  550. memset(zErrMsg, 0, 100);
  551. sprintf(sql,"select * from ocpp_auth_local ");
  552. /* Execute SQL statement */
  553. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  554. if( rc != SQLITE_OK )
  555. {
  556. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  557. }
  558. //return ver;
  559. }
  560. int OCPP_cleanLocalList()
  561. {
  562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  563. char *errMsg = 0;
  564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  565. if (SQLITE_OK != rc)
  566. {
  567. DEBUG_INFO("%s\n",errMsg);
  568. return FALSE;
  569. }
  570. return TRUE;
  571. }
  572. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  573. {
  574. int isSuccess = FALSE;
  575. int ret = 0;
  576. //const char* data = "Callback function called";
  577. char sql[300];
  578. char zErrMsg[200];
  579. memset(sql, 0, 300);
  580. memset(zErrMsg, 0, 200);
  581. 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);
  582. //* Execute SQL statement */
  583. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  584. if( ret != SQLITE_OK )
  585. {
  586. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  587. return isSuccess;
  588. }
  589. memset(sql, 0, 300);
  590. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  591. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. isSuccess = TRUE;
  598. return isSuccess;
  599. }
  600. void OCPP_getIdTagFromLocalList(char idTag[])
  601. {
  602. int rc = 0;
  603. // const char* data = "Callback function called";
  604. char sql[100];
  605. char zErrMsg[100];
  606. memset(sql, 0, 100);
  607. memset(zErrMsg, 0, 100);
  608. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  609. memset(&idTagQuery, 0, sizeof(idTagQuery));
  610. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  611. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  612. /* Execute SQL statement */
  613. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  614. if( rc != SQLITE_OK )
  615. {
  616. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  617. }
  618. //return ver;
  619. }
  620. void OCPP_deleteIdTagFromLocalList(char idTag[])
  621. {
  622. //int ver = 0;
  623. //int isSuccess = FALSE;
  624. int rc = 0;
  625. char sql[100];
  626. char zErrMsg[100];
  627. memset(sql, 0, 100);
  628. memset(zErrMsg, 0, 100);
  629. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  630. //* Execute SQL statement */
  631. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  632. if( rc != SQLITE_OK )
  633. {
  634. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  635. }
  636. }
  637. int getCurrentYear()
  638. {
  639. int result = 0;
  640. time_t CurrentTime;
  641. struct tm *tm;
  642. CurrentTime = time(NULL);
  643. tm=localtime(&CurrentTime);
  644. result = (tm->tm_year + 1900);
  645. return result;
  646. }
  647. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  648. {
  649. int result = PASS;
  650. char* errMsg = NULL;
  651. char sqlStr[8192];
  652. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  653. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  654. {
  655. result = FAIL;
  656. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  657. }
  658. 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));
  659. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  660. {
  661. result = FAIL;
  662. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  663. }
  664. return result;
  665. }
  666. //==========================================
  667. // Check time passed since today
  668. //==========================================
  669. long long DiffTimebWithNow(struct timeb ST)
  670. {
  671. //return milli-second
  672. struct timeb ET;
  673. long long StartTime,StopTime;
  674. ftime(&ET);
  675. StartTime=(long long)ST.time;
  676. StopTime=(long long)ET.time;
  677. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  678. }
  679. int getTimePassSinceToday(uint8_t gun_index)
  680. {
  681. int result = -1;
  682. static time_t lastTime[4];
  683. time_t t;
  684. struct tm *tmStartToday;
  685. struct timeb tbStartToday;
  686. t=time(NULL);
  687. if(difftime(t, lastTime[gun_index])>0)
  688. {
  689. tmStartToday=localtime(&t);
  690. tmStartToday->tm_hour = 0;
  691. tmStartToday->tm_min = 0;
  692. tmStartToday->tm_sec = 0;
  693. tbStartToday.time = mktime(tmStartToday);
  694. tbStartToday.millitm = 0;
  695. result = DiffTimebWithNow(tbStartToday)/1000;
  696. lastTime[gun_index] = t;
  697. }
  698. return result;
  699. }
  700. void getNowDatetime(uint8_t *data)
  701. {
  702. time_t t = time(NULL);
  703. struct tm tm = *localtime(&t);
  704. 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);
  705. }
  706. int syncDateTimeRTC(uint8_t *data)
  707. {
  708. struct ParsingResult
  709. {
  710. int result;
  711. int scanedElement;
  712. int year;
  713. int month;
  714. int mday;
  715. int hour;
  716. int min;
  717. int sec;
  718. int tz_hour;
  719. int tz_min;
  720. float minSec;
  721. }result;
  722. struct tm tmOrg;
  723. struct tm *tmTarget;
  724. struct timeb tbTarget;
  725. char buf[128];
  726. memset(&result, 0x00, sizeof(struct ParsingResult));
  727. result.result = PASS;
  728. if(strstr((char*)data, ".") != NULL)
  729. {
  730. // Original data with mini second
  731. if(strstr((char*)data, "Z") != NULL)
  732. {
  733. // Original data with Z
  734. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  735. &result.year,
  736. &result.month,
  737. &result.mday,
  738. &result.hour,
  739. &result.min,
  740. &result.sec,
  741. &result.minSec);
  742. }
  743. else
  744. {
  745. // Original data without Z
  746. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  747. &result.year,
  748. &result.month,
  749. &result.mday,
  750. &result.hour,
  751. &result.min,
  752. &result.sec,
  753. &result.minSec,
  754. &result.tz_hour,
  755. &result.tz_min);
  756. }
  757. }
  758. else
  759. {
  760. // Original data without mini second
  761. if(strstr((char*)data, "Z") != NULL)
  762. {
  763. // Original data with Z
  764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  765. &result.year,
  766. &result.month,
  767. &result.mday,
  768. &result.hour,
  769. &result.min,
  770. &result.sec);
  771. }
  772. else
  773. {
  774. // Original data without Z
  775. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  776. &result.year,
  777. &result.month,
  778. &result.mday,
  779. &result.hour,
  780. &result.min,
  781. &result.sec,
  782. &result.tz_hour,
  783. &result.tz_min);
  784. }
  785. }
  786. tmOrg.tm_year = result.year - 1900;
  787. tmOrg.tm_mon = result.month - 1;
  788. tmOrg.tm_mday = result.mday;
  789. tmOrg.tm_hour = result.hour;
  790. tmOrg.tm_min = result.min;
  791. tmOrg.tm_sec = result.sec;
  792. tmOrg.tm_gmtoff = 0;
  793. tbTarget.time = mktime(&tmOrg);
  794. tbTarget.timezone = 0;
  795. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  796. tmTarget = gmtime(&tbTarget.time);
  797. 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);
  798. //DEBUG_INFO(" org date time: %s\n", data);
  799. //DEBUG_INFO("parse date time: %s\n", buf);
  800. system(buf);
  801. system("/sbin/hwclock -w --systohc");
  802. if(result.scanedElement < 6)
  803. result.result = FAIL;
  804. return result.result;
  805. }
  806. //==========================================
  807. // GetCompositeSchedule logic related function
  808. //==========================================
  809. int DiffTimebSec(struct timeb ST, struct timeb ET)
  810. {
  811. //return milli-second
  812. unsigned int StartTime,StopTime;
  813. StartTime=(unsigned int)ST.time;
  814. StopTime=(unsigned int)ET.time;
  815. return (StopTime-StartTime);
  816. }
  817. int DiffTimebWithNowSec(struct timeb ST)
  818. {
  819. //return milli-second
  820. struct timeb ET;
  821. unsigned int StartTime,StopTime;
  822. ftime(&ET);
  823. StartTime=(unsigned int)ST.time;
  824. StopTime=(unsigned int)ET.time;
  825. return (StopTime-StartTime);
  826. }
  827. int getStartStop(uint8_t *start, uint8_t *stop)
  828. {
  829. int result = -1;
  830. struct tm tmStart;
  831. struct timeb tbStart;
  832. struct tm tmStop;
  833. struct timeb tbStop;
  834. if((sscanf((char*)start, "%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) &&
  835. (sscanf((char*)stop, "%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))
  836. {
  837. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  838. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  839. tmStart.tm_year -= 1900;
  840. tmStart.tm_mon -= 1;
  841. tbStart.time = mktime(&tmStart);
  842. tbStart.millitm = 0;
  843. tmStop.tm_year -= 1900;
  844. tmStop.tm_mon -= 1;
  845. tbStop.time = mktime(&tmStop);
  846. tbStop.millitm = 0;
  847. result = DiffTimebSec(tbStart, tbStop);
  848. //DEBUG_INFO("getStartStop(): %d\n", result);
  849. }
  850. else
  851. {
  852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  853. }
  854. return result;
  855. }
  856. int isOvertNow(uint8_t *start)
  857. {
  858. int result = NO;
  859. struct tm tmStart;
  860. struct timeb tbStart;
  861. if((sscanf((char*)start, "%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))
  862. {
  863. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  864. tmStart.tm_year -= 1900;
  865. tmStart.tm_mon -= 1;
  866. tbStart.time = mktime(&tmStart);
  867. tbStart.millitm = 0;
  868. if(DiffTimebWithNowSec(tbStart) <= 0)
  869. result = NO;
  870. else
  871. result = YES;
  872. }
  873. else
  874. {
  875. DEBUG_WARN("Start date parsing error.\n");
  876. }
  877. return result;
  878. }
  879. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  880. {
  881. int result = -1;
  882. struct tm tmStart;
  883. struct timeb tbStart;
  884. struct tm tmStop;
  885. struct timeb tbStop;
  886. if((sscanf((char*)start, "%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) &&
  887. (sscanf((char*)stop, "%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))
  888. {
  889. tmStart.tm_year -= 1900;
  890. tmStart.tm_mon -= 1;
  891. tbStart.time = mktime(&tmStart);
  892. tbStart.millitm = 0;
  893. tmStop.tm_year -= 1900;
  894. tmStop.tm_mon -= 1;
  895. tbStop.time = mktime(&tmStop);
  896. tbStop.millitm = 0;
  897. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  898. }
  899. return result;
  900. }
  901. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  902. {
  903. FILE *fp;
  904. char profileFileName[128];
  905. char *line = NULL;
  906. size_t len = 0;
  907. time_t CurrentTime;
  908. struct tm *tmComposite;
  909. struct StructChargingProfile maxProfile;
  910. struct StructChargingProfile defaultTxProfile;
  911. struct StructChargingProfile txProfile;
  912. struct StructChargingSchedulePeriod tmpPeriod;
  913. uint8_t limitMax=0;
  914. uint8_t limitDef=0;
  915. uint8_t limitTx=0;
  916. int compositePeriodIdx = 0;
  917. CurrentTime = time(NULL);
  918. tmComposite=localtime(&CurrentTime);
  919. 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);
  920. if(isUnitA)
  921. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  922. else
  923. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  924. compositeProfile->ChargingSchedule.Duration = durationReq;
  925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  926. {
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  929. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  930. }
  931. compositeProfile->ChargingProfileId = 0;
  932. compositeProfile->StackLevel = 99 ;
  933. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  934. maxProfile.ChargingProfileId = -1;
  935. defaultTxProfile.ChargingProfileId = -1;
  936. txProfile.ChargingProfileId = -1;
  937. maxProfile.ChargingSchedule.Duration = -1;
  938. defaultTxProfile.ChargingSchedule.Duration = -1;
  939. txProfile.ChargingSchedule.Duration = -1;
  940. system("rm -f /tmp/*.json");
  941. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  942. /*
  943. * Search valid charging profile
  944. */
  945. //DEBUG_INFO("====================================\n");
  946. // Search tx profile
  947. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  948. if((access(profileFileName, F_OK))!=-1)
  949. {
  950. fp = fopen(profileFileName, "r");
  951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  952. {
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  955. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  956. }
  957. txProfile.ChargingProfileId = -1;
  958. txProfile.StackLevel = -1;
  959. while(getline(&line, &len, fp) != -1)
  960. {
  961. json_object *obj = NULL;
  962. obj = json_tokener_parse(line);
  963. if(is_error(obj))
  964. {
  965. DEBUG_ERROR("Parse txProfile from file error.\n");
  966. }
  967. else
  968. {
  969. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  970. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  971. )
  972. {
  973. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  974. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. )
  976. {
  977. struct tm tmFrom, tmTo;
  978. struct timeb tbFrom, tbTo;
  979. 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) &&
  980. (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))
  981. {
  982. tmFrom.tm_year -= 1900;
  983. tmFrom.tm_mon -= 1;
  984. tbFrom.time = mktime(&tmFrom);
  985. tmTo.tm_year -= 1900;
  986. tmTo.tm_mon -= 1;
  987. tbTo.time = mktime(&tmTo);
  988. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  989. {
  990. if(txProfile.ChargingProfileId == -1)
  991. DEBUG_INFO("TxProfile found.\n");
  992. else
  993. DEBUG_INFO("TxProfile updated.\n");
  994. // Required item
  995. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  996. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  997. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  998. if(isUnitA)
  999. {
  1000. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1001. 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++)
  1002. {
  1003. 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"));
  1004. 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?
  1005. 3:
  1006. 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")));
  1007. 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")));
  1008. }
  1009. }
  1010. else
  1011. {
  1012. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1013. 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++)
  1014. {
  1015. 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"));
  1016. 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?
  1017. 3:
  1018. 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")));
  1019. 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));
  1020. }
  1021. }
  1022. // Optional item
  1023. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1024. {
  1025. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1026. }
  1027. else
  1028. {
  1029. sprintf((char*)txProfile.ValidFrom, " ");
  1030. }
  1031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1032. {
  1033. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1034. }
  1035. else
  1036. {
  1037. sprintf((char*)txProfile.ValidTo, " ");
  1038. }
  1039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1040. {
  1041. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1042. }
  1043. else
  1044. {
  1045. sprintf((char*)txProfile.RecurrencyKind, " ");
  1046. }
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1048. {
  1049. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1050. }
  1051. else
  1052. {
  1053. txProfile.TransactionId = -1;
  1054. }
  1055. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1056. {
  1057. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1058. }
  1059. else
  1060. {
  1061. txProfile.ChargingSchedule.Duration = 86400;
  1062. }
  1063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1064. {
  1065. 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")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1070. }
  1071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1072. {
  1073. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1074. }
  1075. else
  1076. {
  1077. txProfile.ChargingSchedule.MinChargingRate = -1;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. else
  1083. {
  1084. if(txProfile.ChargingProfileId == -1)
  1085. DEBUG_INFO("TxProfile found.\n");
  1086. else
  1087. DEBUG_INFO("TxProfile updated.\n");
  1088. // Required item
  1089. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1090. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1091. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1092. if(isUnitA)
  1093. {
  1094. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1095. 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++)
  1096. {
  1097. 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"));
  1098. 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?
  1099. 3:
  1100. 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")));
  1101. 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")));
  1102. }
  1103. }
  1104. else
  1105. {
  1106. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1107. 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++)
  1108. {
  1109. 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"));
  1110. 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?
  1111. 3:
  1112. 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")));
  1113. 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));
  1114. }
  1115. }
  1116. // Optional item
  1117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1118. {
  1119. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1120. }
  1121. else
  1122. {
  1123. sprintf((char*)txProfile.ValidFrom, " ");
  1124. }
  1125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1126. {
  1127. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1128. }
  1129. else
  1130. {
  1131. sprintf((char*)txProfile.ValidTo, " ");
  1132. }
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.RecurrencyKind, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1142. {
  1143. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1144. }
  1145. else
  1146. {
  1147. txProfile.TransactionId = -1;
  1148. }
  1149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1150. {
  1151. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1152. }
  1153. else
  1154. {
  1155. txProfile.ChargingSchedule.Duration = 86400;
  1156. }
  1157. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1158. {
  1159. 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")));
  1160. }
  1161. else
  1162. {
  1163. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.MinChargingRate = -1;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. json_object_put(obj);
  1177. }
  1178. fclose(fp);
  1179. /*
  1180. if(txProfile.ChargingProfileId != -1)
  1181. {
  1182. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1183. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1184. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1185. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1186. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1187. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1188. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1189. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1190. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1191. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1192. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1194. {
  1195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1196. {
  1197. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1198. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1199. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1200. }
  1201. }
  1202. }
  1203. else
  1204. DEBUG_INFO("TxProfile not found.\n");*/
  1205. }
  1206. // Search default tx profile
  1207. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1208. if((access(profileFileName, F_OK))==-1)
  1209. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1210. if((access(profileFileName, F_OK))!=-1)
  1211. {
  1212. fp = fopen(profileFileName, "r");
  1213. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1214. {
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1218. }
  1219. defaultTxProfile.ChargingProfileId = -1;
  1220. defaultTxProfile.StackLevel = -1;
  1221. while(getline(&line, &len, fp) != -1)
  1222. {
  1223. json_object *obj = NULL;
  1224. obj = json_tokener_parse(line);
  1225. if(is_error(obj))
  1226. {
  1227. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1228. }
  1229. else
  1230. {
  1231. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1232. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1233. )
  1234. {
  1235. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1236. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1237. )
  1238. {
  1239. struct tm tmFrom, tmTo;
  1240. struct timeb tbFrom, tbTo;
  1241. 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) &&
  1242. (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))
  1243. {
  1244. tmFrom.tm_year -= 1900;
  1245. tmFrom.tm_mon -= 1;
  1246. tbFrom.time = mktime(&tmFrom);
  1247. tmTo.tm_year -= 1900;
  1248. tmTo.tm_mon -= 1;
  1249. tbTo.time = mktime(&tmTo);
  1250. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1251. {
  1252. if(defaultTxProfile.ChargingProfileId == -1)
  1253. DEBUG_INFO("TxDefaultProfile found.\n");
  1254. else
  1255. DEBUG_INFO("TxDefaultProfile updated.\n");
  1256. // Required item
  1257. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1258. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1259. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1260. if(isUnitA)
  1261. {
  1262. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1263. 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++)
  1264. {
  1265. 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"));
  1266. 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?
  1267. 3:
  1268. 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")));
  1269. 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")));
  1270. }
  1271. }
  1272. else
  1273. {
  1274. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1275. 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++)
  1276. {
  1277. 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"));
  1278. 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?
  1279. 3:
  1280. 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")));
  1281. 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));
  1282. }
  1283. }
  1284. // Optional item
  1285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1286. {
  1287. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1292. }
  1293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1294. {
  1295. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1296. }
  1297. else
  1298. {
  1299. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1300. }
  1301. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1302. {
  1303. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1304. }
  1305. else
  1306. {
  1307. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1308. }
  1309. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1310. {
  1311. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1312. }
  1313. else
  1314. {
  1315. defaultTxProfile.TransactionId = -1;
  1316. }
  1317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1318. {
  1319. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1320. }
  1321. else
  1322. {
  1323. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1324. }
  1325. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1326. {
  1327. 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")));
  1328. }
  1329. else
  1330. {
  1331. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1332. }
  1333. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1334. {
  1335. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1336. }
  1337. else
  1338. {
  1339. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if(defaultTxProfile.ChargingProfileId == -1)
  1347. DEBUG_INFO("TxDefaultProfile found.\n");
  1348. else
  1349. DEBUG_INFO("TxDefaultProfile updated.\n");
  1350. // Required item
  1351. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1352. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1353. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1354. if(isUnitA)
  1355. {
  1356. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1357. 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++)
  1358. {
  1359. 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"));
  1360. 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?
  1361. 3:
  1362. 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")));
  1363. 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")));
  1364. }
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1369. 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++)
  1370. {
  1371. 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"));
  1372. 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?
  1373. 3:
  1374. 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")));
  1375. 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));
  1376. }
  1377. }
  1378. // Optional item
  1379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1380. {
  1381. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1386. }
  1387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1388. {
  1389. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1390. }
  1391. else
  1392. {
  1393. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1394. }
  1395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1396. {
  1397. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1398. }
  1399. else
  1400. {
  1401. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1402. }
  1403. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1404. {
  1405. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1406. }
  1407. else
  1408. {
  1409. defaultTxProfile.TransactionId = -1;
  1410. }
  1411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1414. }
  1415. else
  1416. {
  1417. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1418. }
  1419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1420. {
  1421. 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")));
  1422. }
  1423. else
  1424. {
  1425. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1426. }
  1427. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1428. {
  1429. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1430. }
  1431. else
  1432. {
  1433. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. json_object_put(obj);
  1439. }
  1440. fclose(fp);
  1441. /*
  1442. if(defaultTxProfile.ChargingProfileId != -1)
  1443. {
  1444. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1445. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1446. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1447. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1448. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1449. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1450. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1451. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1452. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1453. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1454. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1456. {
  1457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1458. {
  1459. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1460. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1461. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1462. }
  1463. }
  1464. }
  1465. else
  1466. DEBUG_INFO("TxDefaultProfile not found.\n");
  1467. DEBUG_INFO("------------------------------------\n");*/
  1468. }
  1469. // Search max profile
  1470. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1471. if((access(profileFileName, F_OK))!=-1)
  1472. {
  1473. fp = fopen(profileFileName, "r");
  1474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1475. {
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1479. }
  1480. maxProfile.ChargingProfileId = -1;
  1481. maxProfile.StackLevel = -1;
  1482. while(getline(&line, &len, fp) != -1)
  1483. {
  1484. json_object *obj = NULL;
  1485. obj = json_tokener_parse(line);
  1486. if(is_error(obj))
  1487. {
  1488. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1489. }
  1490. else
  1491. {
  1492. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1493. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1494. )
  1495. {
  1496. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1497. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. )
  1499. {
  1500. struct tm tmFrom, tmTo;
  1501. struct timeb tbFrom, tbTo;
  1502. 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) &&
  1503. (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))
  1504. {
  1505. tmFrom.tm_year -= 1900;
  1506. tmFrom.tm_mon -= 1;
  1507. tbFrom.time = mktime(&tmFrom);
  1508. tmTo.tm_year -= 1900;
  1509. tmTo.tm_mon -= 1;
  1510. tbTo.time = mktime(&tmTo);
  1511. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1512. {
  1513. if(maxProfile.ChargingProfileId == -1)
  1514. DEBUG_INFO("MaxProfile found.\n");
  1515. else
  1516. DEBUG_INFO("MaxProfile updated.\n");
  1517. // Required item
  1518. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1519. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1520. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1521. if(isUnitA)
  1522. {
  1523. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1524. 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++)
  1525. {
  1526. 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"));
  1527. 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?
  1528. 3:
  1529. 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")));
  1530. 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")));
  1531. }
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1536. 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++)
  1537. {
  1538. 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"));
  1539. 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?
  1540. 3:
  1541. 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")));
  1542. 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));
  1543. }
  1544. }
  1545. // Optional item
  1546. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1547. {
  1548. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1549. }
  1550. else
  1551. {
  1552. sprintf((char*)maxProfile.ValidFrom, " ");
  1553. }
  1554. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1555. {
  1556. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1557. }
  1558. else
  1559. {
  1560. sprintf((char*)maxProfile.ValidTo, " ");
  1561. }
  1562. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1563. {
  1564. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1565. }
  1566. else
  1567. {
  1568. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1569. }
  1570. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1571. {
  1572. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1573. }
  1574. else
  1575. {
  1576. maxProfile.TransactionId = -1;
  1577. }
  1578. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1579. {
  1580. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1581. }
  1582. else
  1583. {
  1584. maxProfile.ChargingSchedule.Duration = 86400;
  1585. }
  1586. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1587. {
  1588. 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")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1593. }
  1594. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1595. {
  1596. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1597. }
  1598. else
  1599. {
  1600. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1601. }
  1602. }
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if(maxProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("MaxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("MaxProfile updated.\n");
  1611. // Required item
  1612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. 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++)
  1619. {
  1620. 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"));
  1621. 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?
  1622. 3:
  1623. 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")));
  1624. 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")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. 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++)
  1631. {
  1632. 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"));
  1633. 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?
  1634. 3:
  1635. 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")));
  1636. 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));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)maxProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)maxProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. maxProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. maxProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. 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")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. json_object_put(obj);
  1700. }
  1701. fclose(fp);
  1702. /*
  1703. if(maxProfile.ChargingProfileId !=-1)
  1704. {
  1705. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1706. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1707. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1708. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1709. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1710. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1711. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1712. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1713. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1714. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1715. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1719. {
  1720. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1721. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1722. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1723. }
  1724. }
  1725. }
  1726. else
  1727. DEBUG_INFO("MaxProfile not found.\n");
  1728. DEBUG_INFO("------------------------------------\n");*/
  1729. }
  1730. /*
  1731. * Align found profile start schedule & periods
  1732. */
  1733. //DEBUG_INFO("====================================\n");
  1734. /*
  1735. // For local test usage, force modify found profile start schedule info
  1736. 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);
  1737. 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);
  1738. 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);
  1739. */
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1743. {
  1744. if(txProfile.ChargingSchedule.Duration != -1)
  1745. {
  1746. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1747. 0:
  1748. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1749. }
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1753. {
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1755. 0:
  1756. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1757. if(idxPeriod > 0)
  1758. {
  1759. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1760. {
  1761. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1768. {
  1769. if(txProfile.ChargingSchedule.Duration != -1)
  1770. {
  1771. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1772. 0:
  1773. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1774. }
  1775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1776. {
  1777. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1778. {
  1779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1780. 0:
  1781. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1782. if(idxPeriod > 0)
  1783. {
  1784. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1785. {
  1786. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. else
  1793. {
  1794. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1795. {
  1796. if(txProfile.ChargingSchedule.Duration != -1)
  1797. {
  1798. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1799. 0:
  1800. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1801. }
  1802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1803. {
  1804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1805. {
  1806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1807. 0:
  1808. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1809. if(idxPeriod > 0)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1834. if(idxPeriod > 0)
  1835. {
  1836. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1837. {
  1838. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. /*
  1846. DEBUG_INFO("txProfile after align.\n");
  1847. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1848. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1849. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1850. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1851. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1852. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1853. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1854. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1855. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1856. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1857. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1861. {
  1862. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1863. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1864. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1865. }
  1866. }*/
  1867. }
  1868. if(defaultTxProfile.ChargingProfileId != -1)
  1869. {
  1870. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1871. {
  1872. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1873. {
  1874. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1875. 0:
  1876. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1877. }
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1881. {
  1882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1883. 0:
  1884. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1885. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1886. {
  1887. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1888. }
  1889. if(idxPeriod > 0)
  1890. {
  1891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1892. {
  1893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1902. {
  1903. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1904. 0:
  1905. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1906. }
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1910. {
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1912. 0:
  1913. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1915. {
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1917. }
  1918. if(idxPeriod > 0)
  1919. {
  1920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1921. {
  1922. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1931. {
  1932. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1933. {
  1934. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1935. 0:
  1936. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1937. }
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1941. {
  1942. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1943. 0:
  1944. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1945. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1946. {
  1947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1948. }
  1949. if(idxPeriod > 0)
  1950. {
  1951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1952. {
  1953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1962. {
  1963. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1964. 0:
  1965. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1966. }
  1967. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1968. {
  1969. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1970. {
  1971. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1972. 0:
  1973. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1974. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1975. {
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. }
  1978. if(idxPeriod > 0)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. DEBUG_INFO("defaultTxProfile after align.\n");
  1991. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1992. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1993. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1994. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1995. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1996. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1997. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1998. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1999. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2000. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2001. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2003. {
  2004. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2005. {
  2006. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2007. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2008. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2009. }
  2010. }
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. if(maxProfile.ChargingProfileId != -1)
  2014. {
  2015. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2016. {
  2017. if(maxProfile.ChargingSchedule.Duration != -1)
  2018. {
  2019. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2020. 0:
  2021. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2022. }
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2026. {
  2027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2028. 0:
  2029. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2030. if(idxPeriod > 0)
  2031. {
  2032. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2033. {
  2034. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2041. {
  2042. if(maxProfile.ChargingSchedule.Duration != -1)
  2043. {
  2044. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2045. 0:
  2046. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2047. }
  2048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2049. {
  2050. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2051. {
  2052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2053. 0:
  2054. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2055. if(idxPeriod > 0)
  2056. {
  2057. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2058. {
  2059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. else
  2066. {
  2067. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2068. {
  2069. if(maxProfile.ChargingSchedule.Duration != -1)
  2070. {
  2071. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2072. 0:
  2073. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2074. }
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2078. {
  2079. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2080. 0:
  2081. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2082. if(idxPeriod > 0)
  2083. {
  2084. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2085. {
  2086. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. else
  2093. {
  2094. if(maxProfile.ChargingSchedule.Duration != -1)
  2095. {
  2096. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2097. 0:
  2098. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2099. }
  2100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2101. {
  2102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2103. {
  2104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2105. 0:
  2106. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2107. if(idxPeriod > 0)
  2108. {
  2109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2110. {
  2111. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. /*
  2119. DEBUG_INFO("MaxProfile after align.\n");
  2120. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2121. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2122. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2123. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2124. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2125. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2126. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2127. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2128. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2129. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2130. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2131. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2132. {
  2133. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2134. {
  2135. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2136. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2137. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2138. }
  2139. }
  2140. DEBUG_INFO("------------------------------------\n");*/
  2141. }
  2142. /*
  2143. * Merge to conposite schedule
  2144. */
  2145. //DEBUG_INFO("====================================\n");
  2146. // Find each profile period quantity
  2147. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2148. {
  2149. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2150. limitMax = idx+1;
  2151. }
  2152. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2153. {
  2154. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2155. limitDef = idx+1;
  2156. }
  2157. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2158. {
  2159. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2160. limitTx = idx+1;
  2161. }
  2162. // TxProfile found, composite schedule based on it
  2163. if(txProfile.ChargingProfileId != -1)
  2164. {
  2165. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2166. {
  2167. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2168. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2169. (txProfile.ChargingSchedule.Duration > 0))
  2170. {
  2171. if(maxProfile.ChargingProfileId != -1)
  2172. {
  2173. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2174. {
  2175. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2176. {
  2177. if((maxProfile.ChargingSchedule.Duration > 0))
  2178. {
  2179. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2180. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2181. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2182. }
  2183. else
  2184. {
  2185. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2186. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2187. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2188. }
  2189. }
  2190. if(idxMaxPeriod == (limitMax-1))
  2191. {
  2192. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2193. {
  2194. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2195. {
  2196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2197. compositePeriodIdx++;
  2198. }
  2199. else
  2200. {
  2201. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. else
  2208. {
  2209. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2210. {
  2211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2212. compositePeriodIdx++;
  2213. }
  2214. else
  2215. {
  2216. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2217. }
  2218. }
  2219. }
  2220. if(idxTxPeriod == (limitTx-1))
  2221. {
  2222. if(defaultTxProfile.ChargingProfileId != -1)
  2223. {
  2224. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2225. {
  2226. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2227. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2228. (defaultTxProfile.ChargingSchedule.Duration>0))
  2229. {
  2230. if(maxProfile.ChargingProfileId != -1)
  2231. {
  2232. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2233. {
  2234. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2235. {
  2236. if((maxProfile.ChargingSchedule.Duration > 0))
  2237. {
  2238. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2239. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2240. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2241. }
  2242. else
  2243. {
  2244. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2245. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2246. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2247. }
  2248. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2249. {
  2250. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. // Delete duplicate period
  2261. if(compositePeriodIdx > 1)
  2262. {
  2263. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2264. {
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2266. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2267. compositePeriodIdx -= 1;
  2268. }
  2269. }
  2270. }
  2271. else
  2272. break;
  2273. }
  2274. }
  2275. else
  2276. {
  2277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2294. else if(defaultTxProfile.ChargingProfileId != -1)
  2295. {
  2296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2297. {
  2298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2300. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2301. {
  2302. if(maxProfile.ChargingProfileId != -1)
  2303. {
  2304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2305. {
  2306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2307. {
  2308. if((maxProfile.ChargingSchedule.Duration > 0))
  2309. {
  2310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2313. }
  2314. else
  2315. {
  2316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2319. }
  2320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2321. {
  2322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2323. {
  2324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2325. compositePeriodIdx++;
  2326. }
  2327. else
  2328. {
  2329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2330. }
  2331. }
  2332. // Delete duplicate period
  2333. if(compositePeriodIdx > 1)
  2334. {
  2335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2336. {
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2339. compositePeriodIdx -= 1;
  2340. }
  2341. }
  2342. }
  2343. else
  2344. break;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2350. {
  2351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2352. compositePeriodIdx++;
  2353. }
  2354. else
  2355. {
  2356. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. // Fill other period by MaxProfile
  2363. if(maxProfile.ChargingProfileId != -1)
  2364. {
  2365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2366. {
  2367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2369. (maxProfile.ChargingSchedule.Duration > 0))
  2370. {
  2371. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2372. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2373. {
  2374. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2375. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2376. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2377. }
  2378. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2379. {
  2380. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2383. }
  2384. if(tmpPeriod.Limit != -1)
  2385. {
  2386. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2387. {
  2388. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2389. {
  2390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2391. compositePeriodIdx++;
  2392. }
  2393. else
  2394. {
  2395. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2396. }
  2397. }
  2398. // Delete duplicate period
  2399. if(compositePeriodIdx > 1)
  2400. {
  2401. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2402. {
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2404. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2405. compositePeriodIdx -= 1;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2413. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2414. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2415. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. compositeProfile->ChargingProfileId = 1;
  2421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2424. }
  2425. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2426. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2427. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2428. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2429. }
  2430. if(line)
  2431. free(line);
  2432. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2433. }
  2434. //==========================================
  2435. // Init all share memory
  2436. //==========================================
  2437. int InitShareMemory()
  2438. {
  2439. int result = PASS;
  2440. int MeterSMId;
  2441. //creat ShmSysConfigAndInfo
  2442. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2443. {
  2444. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2445. result = FAIL;
  2446. }
  2447. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2448. {
  2449. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2450. result = FAIL;
  2451. }
  2452. else
  2453. {}
  2454. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2455. {
  2456. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2457. result = FAIL;
  2458. }
  2459. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2460. {
  2461. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2462. result = FAIL;
  2463. }
  2464. else
  2465. {}
  2466. //creat ShmPsuData
  2467. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2468. {
  2469. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2470. result = FAIL;
  2471. }
  2472. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2473. {
  2474. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2475. result = FAIL;
  2476. }
  2477. else
  2478. {}
  2479. //link ShmOCPP16Data
  2480. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2481. {
  2482. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2483. result = FAIL;
  2484. }
  2485. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2486. {
  2487. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2488. result = FAIL;
  2489. }
  2490. else
  2491. {}
  2492. //creat ShmOCPP16DataPH
  2493. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2494. {
  2495. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2496. result = FAIL;
  2497. }
  2498. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2499. {
  2500. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2501. result = FAIL;
  2502. }
  2503. else
  2504. {}
  2505. /****************************** For Initial Settings************************************************/
  2506. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2507. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2508. // allocate Configuration memory address
  2509. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2510. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2513. //offline MeterValue Interval
  2514. TempMeterValueInterval = 0;
  2515. return result;
  2516. }
  2517. int ProcessShareMemory()
  2518. {
  2519. if(InitShareMemory() == FAIL)
  2520. {
  2521. DEBUG_ERROR("InitShareMemory NG\n");
  2522. if(ShmStatusCodeData!=NULL)
  2523. {
  2524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2525. }
  2526. sleep(5);
  2527. return FAIL;
  2528. }
  2529. return PASS;
  2530. }
  2531. void CheckSystemValue(void)
  2532. {
  2533. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2534. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2535. char filenmae[100]={0};
  2536. char str[100]={0};
  2537. int tempIndex = 0;
  2538. //===============================
  2539. // send Heartbeat
  2540. //===============================
  2541. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2542. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2543. {
  2544. clientTime.Heartbeat=time((time_t*)NULL);
  2545. if(server_sign == TRUE)
  2546. {
  2547. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2548. }
  2549. else
  2550. {
  2551. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2552. }
  2553. }
  2554. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2555. {
  2556. //parameter for test
  2557. sendHeartbeatRequest(0);
  2558. //==============================================
  2559. // Reset Waiting Time
  2560. //==============================================
  2561. HeartBeatWithNOResponse += 2;
  2562. }
  2563. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2564. {
  2565. //==========================================
  2566. // csu trigger DataTransferReq
  2567. //==========================================
  2568. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  2569. {
  2570. sendDataTransferRequest(gun_index);
  2571. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  2572. }
  2573. //===============================
  2574. // CSU Trigger Authorize Request
  2575. //===============================
  2576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2577. {
  2578. sendAuthorizeRequest(0);
  2579. authorizeRetryTimes = authorizeRetryTimes + 1;
  2580. if(authorizeRetryTimes < 3)
  2581. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  2582. }
  2583. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2584. {
  2585. authorizeRetryTimes = 0;
  2586. SetOcppConnStatus(FALSE);
  2587. server_sign = FALSE;
  2588. }
  2589. 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))
  2590. {
  2591. sendAuthorizeRequest(0);
  2592. }
  2593. //==============================================
  2594. // CSU Trigger Smart Charging Profilw
  2595. //==============================================
  2596. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2597. {
  2598. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  2599. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2600. }
  2601. //==============================================
  2602. // Charger start transaction
  2603. //==============================================
  2604. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2605. {
  2606. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2607. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  2608. sendStartTransactionRequest(gun_index);
  2609. clientTime.StartTransaction = time((time_t*)NULL);
  2610. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2611. storeTempStopTransaction(gun_index);
  2612. }
  2613. //==============================================
  2614. // Charger stop transaction
  2615. //==============================================
  2616. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2617. {
  2618. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2619. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  2620. sendStopTransactionRequest(gun_index);
  2621. clientTime.StopTransaction = time((time_t*)NULL);
  2622. }
  2623. //==============================================
  2624. // Charger status report
  2625. //==============================================
  2626. //--- Check Mode Change ---//
  2627. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2629. {
  2630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2631. {
  2632. tempIndex = ((gun_index==2) ? 1: 0);
  2633. }
  2634. else
  2635. {
  2636. tempIndex = gun_index;
  2637. }
  2638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2639. {
  2640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2641. {
  2642. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2643. {
  2644. // Sent unplug message for California pricing logic
  2645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2646. {
  2647. uint8_t ts[20];
  2648. getNowDatetime(ts);
  2649. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2650. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2651. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2652. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2653. }
  2654. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2655. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2656. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2657. }
  2658. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2659. {
  2660. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2661. if((access(filenmae,F_OK))!=-1)
  2662. {
  2663. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2664. sprintf(str,"rm -f %s",filenmae);
  2665. system(str);
  2666. }
  2667. }
  2668. #if 1 // for TempStopTransaction
  2669. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2670. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2671. {
  2672. checkTempStopTransaction(gun_index);
  2673. }
  2674. #endif
  2675. }
  2676. }
  2677. }
  2678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2679. {
  2680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2681. {
  2682. tempIndex = ((gun_index==2) ? 1: 0);
  2683. }
  2684. else
  2685. {
  2686. tempIndex = gun_index;
  2687. }
  2688. for (int index = 0; index < CCS_QUANTITY; index++)
  2689. {
  2690. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2691. {
  2692. if((SystemInitial > 0) || (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]*/ )
  2693. {
  2694. // Sent unplug message for California pricing logic
  2695. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2696. {
  2697. uint8_t ts[20];
  2698. getNowDatetime(ts);
  2699. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2700. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2701. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2702. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2703. }
  2704. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2705. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2706. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2707. }
  2708. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2709. {
  2710. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2711. if((access(filenmae,F_OK))!=-1)
  2712. {
  2713. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2714. sprintf(str,"rm -f %s",filenmae);
  2715. system(str);
  2716. }
  2717. }
  2718. #if 1 // for TempStopTransaction
  2719. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2720. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2721. {
  2722. checkTempStopTransaction(gun_index);
  2723. }
  2724. #endif
  2725. }
  2726. }
  2727. }
  2728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2729. {
  2730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2731. {
  2732. tempIndex = ((gun_index==2) ? 1: 0);
  2733. }
  2734. else
  2735. {
  2736. tempIndex = gun_index;
  2737. }
  2738. for (int index = 0; index < GB_QUANTITY; index++)
  2739. {
  2740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2741. {
  2742. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2743. {
  2744. // Sent unplug message for California pricing logic
  2745. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2746. {
  2747. uint8_t ts[20];
  2748. getNowDatetime(ts);
  2749. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2750. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2752. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2753. }
  2754. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2755. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2756. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2757. }
  2758. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2759. {
  2760. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2761. if((access(filenmae,F_OK))!=-1)
  2762. {
  2763. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2764. sprintf(str,"rm -f %s",filenmae);
  2765. system(str);
  2766. }
  2767. }
  2768. #if 1 // for TempStopTransaction
  2769. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2770. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2771. {
  2772. checkTempStopTransaction(gun_index);
  2773. }
  2774. #endif
  2775. }
  2776. }
  2777. }
  2778. else if(gunType[gun_index] == GUN_TYPE_DO)
  2779. {
  2780. tempIndex = gun_index;
  2781. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2782. {
  2783. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2784. {
  2785. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2786. {
  2787. // Sent unplug message for California pricing logic
  2788. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2789. {
  2790. uint8_t ts[20];
  2791. getNowDatetime(ts);
  2792. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2793. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2794. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2795. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2796. }
  2797. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2798. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2799. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2800. }
  2801. 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_PREPARING))) // complete
  2802. {
  2803. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2804. if((access(filenmae,F_OK))!=-1)
  2805. {
  2806. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2807. sprintf(str,"rm -f %s",filenmae);
  2808. system(str);
  2809. }
  2810. }
  2811. #if 1 // for TempStopTransaction
  2812. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2813. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2814. {
  2815. checkTempStopTransaction(gun_index);
  2816. }
  2817. #endif
  2818. }
  2819. }
  2820. }
  2821. else
  2822. {
  2823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2824. {
  2825. tempIndex = 2;
  2826. }
  2827. else
  2828. {
  2829. tempIndex = gun_index;
  2830. }
  2831. for (int index = 0; index < AC_QUANTITY; index++)
  2832. {
  2833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2834. {
  2835. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2836. {
  2837. // Sent unplug message for California pricing logic
  2838. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2839. {
  2840. uint8_t ts[20];
  2841. getNowDatetime(ts);
  2842. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2843. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2844. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2845. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2846. }
  2847. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2848. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2849. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2850. }
  2851. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2852. {
  2853. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2854. if((access(filenmae,F_OK))!=-1)
  2855. {
  2856. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2857. sprintf(str,"rm -f %s",filenmae);
  2858. system(str);
  2859. }
  2860. }
  2861. #if 1 // for TempStopTransaction
  2862. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2863. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2864. {
  2865. checkTempStopTransaction(gun_index);
  2866. }
  2867. #endif
  2868. }
  2869. }// END
  2870. }
  2871. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2872. (
  2873. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2874. )
  2875. )
  2876. {
  2877. if(SystemInitial > 0)
  2878. SystemInitial -= 1;
  2879. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  2880. sendStatusNotificationRequest(gun_index);
  2881. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2882. }
  2883. //==============================================
  2884. // Meter report
  2885. //==============================================
  2886. // Trigger MeterValue
  2887. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2888. {
  2889. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2890. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2891. }
  2892. // ClockAlign MeterValue
  2893. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2894. {
  2895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2896. {
  2897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2898. {
  2899. tempIndex = ((gun_index==2) ? 1: 0);
  2900. }
  2901. else
  2902. {
  2903. tempIndex = gun_index;
  2904. }
  2905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2906. {
  2907. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2909. {
  2910. reqClockAlignMeter[gun_index] = 1;
  2911. }
  2912. }// End for CHAdeMO
  2913. }
  2914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2915. {
  2916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2917. {
  2918. tempIndex = ((gun_index==2) ? 1: 0);
  2919. }
  2920. else
  2921. {
  2922. tempIndex = gun_index;
  2923. }
  2924. for (int index = 0; index < CCS_QUANTITY; index++)
  2925. {
  2926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2927. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2928. {
  2929. reqClockAlignMeter[gun_index] = 1;
  2930. }
  2931. } // End for CCS
  2932. }
  2933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2934. {
  2935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2936. {
  2937. tempIndex = ((gun_index==2) ? 1: 0);
  2938. }
  2939. else
  2940. {
  2941. tempIndex = gun_index;
  2942. }
  2943. for (int index = 0; index < GB_QUANTITY; index++)
  2944. {
  2945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2946. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2947. {
  2948. reqClockAlignMeter[gun_index] = 1;
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. reqClockAlignMeter[gun_index] = 1;
  2961. }
  2962. }
  2963. }
  2964. else
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2967. {
  2968. tempIndex = 2;
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < AC_QUANTITY; index++)
  2975. {
  2976. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2977. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2978. {
  2979. reqClockAlignMeter[gun_index] = 1;
  2980. }
  2981. }//End for AC
  2982. }
  2983. if(reqClockAlignMeter[gun_index] == 1)
  2984. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2985. }
  2986. // Sample period MeterValue
  2987. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  2988. {
  2989. //check Transaction active
  2990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2991. {
  2992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2993. {
  2994. tempIndex = ((gun_index==2) ? 1: 0);
  2995. }
  2996. else
  2997. {
  2998. tempIndex = gun_index;
  2999. }
  3000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3001. {
  3002. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3003. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3004. {
  3005. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3006. {
  3007. reqSampleMeter[gun_index] = 1;
  3008. }
  3009. }
  3010. }// End for CHAdeMO
  3011. }
  3012. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3013. {
  3014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3015. {
  3016. tempIndex = ((gun_index==2) ? 1: 0);
  3017. }
  3018. else
  3019. {
  3020. tempIndex = gun_index;
  3021. }
  3022. for (int index = 0; index < CCS_QUANTITY; index++)
  3023. {
  3024. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3025. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3026. {
  3027. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3028. {
  3029. reqSampleMeter[gun_index] = 1;
  3030. }
  3031. }
  3032. } // End for CCS
  3033. }
  3034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3035. {
  3036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3037. {
  3038. tempIndex = ((gun_index==2) ? 1: 0);
  3039. }
  3040. else
  3041. {
  3042. tempIndex = gun_index;
  3043. }
  3044. for (int index = 0; index < GB_QUANTITY; index++)
  3045. {
  3046. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3047. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3048. {
  3049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3050. {
  3051. reqSampleMeter[gun_index] = 1;
  3052. }
  3053. }
  3054. }// End for GB
  3055. }
  3056. else if(gunType[gun_index] == GUN_TYPE_DO)
  3057. {
  3058. tempIndex = gun_index;
  3059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3060. {
  3061. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3062. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3063. {
  3064. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3065. {
  3066. reqSampleMeter[gun_index] = 1;
  3067. }
  3068. }
  3069. }
  3070. }
  3071. else
  3072. {
  3073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3074. {
  3075. tempIndex = 2;
  3076. }
  3077. else
  3078. {
  3079. tempIndex = gun_index;
  3080. }
  3081. for (int index = 0; index < AC_QUANTITY; index++)
  3082. {
  3083. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3084. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3085. {
  3086. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3087. {
  3088. reqSampleMeter[gun_index] = 1;
  3089. }
  3090. }
  3091. }//End for AC
  3092. }
  3093. if(reqSampleMeter[gun_index] == 1)
  3094. {
  3095. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3096. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3097. storeTempStopTransaction(gun_index);
  3098. }
  3099. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3100. }
  3101. //==============================================
  3102. // Check Connector reserved
  3103. //==============================================
  3104. //===============================
  3105. // Check if Reserve is expired
  3106. //===============================
  3107. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3108. {
  3109. double diff_t;
  3110. struct tm tp;
  3111. // current time
  3112. time_t t = time(NULL);
  3113. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3114. tp.tm_isdst = -1;
  3115. time_t utc = mktime(&tp);
  3116. diff_t = difftime(utc, t);
  3117. if(diff_t <= 0)
  3118. {
  3119. DEBUG_INFO("reserve expired.\n");
  3120. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3121. }
  3122. }//END OF Check if Reserve is expired
  3123. //==========================================
  3124. // csu trigger FirmwareStatusNotificationReq
  3125. //==========================================
  3126. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3127. {
  3128. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3129. }
  3130. //==========================================
  3131. // csu trigger DiagnosticsStatusNotificationReq
  3132. //==========================================
  3133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3134. {
  3135. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3136. }
  3137. //==========================================
  3138. // csu trigger CancelReservationConf
  3139. //==========================================
  3140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3141. {
  3142. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3143. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3144. }
  3145. //==========================================
  3146. // csu trigger ChangeAvailabilityConf
  3147. //==========================================
  3148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3149. {
  3150. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3151. }
  3152. //==========================================
  3153. // csu trigger UnlockConnectorConf
  3154. //==========================================
  3155. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3156. {
  3157. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3158. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3159. }
  3160. //==========================================
  3161. // csu trigger ReserveNowConf
  3162. //==========================================
  3163. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3164. {
  3165. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3166. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3167. }
  3168. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3169. {
  3170. sendSignCertificateRequest();
  3171. }
  3172. }
  3173. }
  3174. //==========================================
  3175. // send request routine
  3176. //==========================================
  3177. int sendAuthorizeRequest(int gun_index)
  3178. {
  3179. mtrace();
  3180. int result = FAIL;
  3181. char message[100]={0};
  3182. char guid[37];
  3183. char tempdata[65]={0};
  3184. DEBUG_INFO("sendAuthorizeRequest...\n");
  3185. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3186. //Local Authorize
  3187. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3188. {
  3189. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3190. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3191. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3192. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3193. result = PASS;
  3194. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3195. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3196. authorizeRetryTimes = 0;
  3197. return result;
  3198. }
  3199. 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))||
  3200. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3201. {
  3202. // Query from cache
  3203. DEBUG_INFO("Authorize from cache.\n");
  3204. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3205. // Query from list
  3206. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3207. {
  3208. DEBUG_INFO("Authorize from list.\n");
  3209. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3210. }
  3211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3212. {
  3213. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3214. {
  3215. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3216. }
  3217. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3218. {
  3219. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3220. }
  3221. if(!GetOcppConnStatus())
  3222. {
  3223. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3224. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3225. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3226. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3227. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3228. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3229. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3230. authorizeRetryTimes = 0;
  3231. return result;
  3232. }
  3233. }
  3234. else
  3235. {
  3236. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3237. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3238. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3239. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3240. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3241. else
  3242. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3243. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3244. result = PASS;
  3245. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3246. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3247. authorizeRetryTimes = 0;
  3248. return result;
  3249. }
  3250. }
  3251. //initialize struct Authorize
  3252. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3253. //get data from shared memory
  3254. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3255. random_uuid(guid);
  3256. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3257. LWS_Send(message);
  3258. sprintf(tempdata, "Authorize,%d", gun_index);
  3259. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3260. {
  3261. result = PASS;
  3262. DEBUG_INFO("Authorize mapItem pass\n");
  3263. }
  3264. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3265. return result;
  3266. }
  3267. int sendBootNotificationRequest(void)
  3268. {
  3269. mtrace();
  3270. int result = FAIL;
  3271. char message[500]={0}, payload[700]={0};
  3272. char guid[37]={0};
  3273. char tempdata[65]={0};
  3274. // Fill BootNotification fields
  3275. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3276. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3277. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3278. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3279. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3280. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3281. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3282. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3283. ShmOCPP16DataPH->ChargeBoxId
  3284. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3285. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3286. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3287. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3288. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3289. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3290. random_uuid(guid);
  3291. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3292. LWS_Send(message);
  3293. sprintf(tempdata, "BootNotification,0");
  3294. 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*/)
  3295. {
  3296. result = PASS;
  3297. }
  3298. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3299. strcpy(queuedata,message);
  3300. return result;
  3301. }
  3302. int sendDataTransferRequest(int gun_index)
  3303. {
  3304. mtrace();
  3305. char message[1000]={0};
  3306. char guid[37]={0};
  3307. char tempdata[65]={0};
  3308. int result = FAIL;
  3309. random_uuid(guid);
  3310. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3311. MESSAGE_TYPE_CALL,
  3312. guid,
  3313. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3314. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3315. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3316. LWS_Send(message);
  3317. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3318. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3319. {
  3320. result = PASS;
  3321. DEBUG_INFO("DataTransfer mapItem pass\n");
  3322. }
  3323. return result;
  3324. }
  3325. int sendDiagnosticsStatusNotificationRequest(char *status)
  3326. {
  3327. mtrace();
  3328. int result = FAIL;
  3329. char message[110]={0};
  3330. char guid[37]={0};
  3331. char tempdata[65]={0};
  3332. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3333. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3334. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3335. random_uuid(guid);
  3336. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3337. LWS_SendNow(message);
  3338. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3339. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3340. {
  3341. result = PASS;
  3342. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3343. }
  3344. //#ifdef SystemLogMessage
  3345. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3346. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3347. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3348. //#endif
  3349. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3350. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3351. //record status
  3352. if(strcmp(status,"Idle")==0)
  3353. {
  3354. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3355. }
  3356. else if(strcmp(status,"Uploaded")==0)
  3357. {
  3358. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3359. }
  3360. else if(strcmp(status,"UploadFailed")==0)
  3361. {
  3362. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3363. }
  3364. else if(strcmp(status,"Uploading")==0)
  3365. {
  3366. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3367. }
  3368. return result;
  3369. }
  3370. int sendFirmwareStatusNotificationRequest(char *status)
  3371. {
  3372. mtrace();
  3373. int result = FAIL;
  3374. char message[110]={0};
  3375. char guid[37]={0};
  3376. char tempdata[65]={0};
  3377. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3378. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3379. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3380. random_uuid(guid);
  3381. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3382. LWS_SendNow(message);
  3383. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3384. 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*/)
  3385. {
  3386. result = PASS;
  3387. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3388. }
  3389. //#ifdef SystemLogMessage
  3390. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3391. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3392. //#endif
  3393. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3394. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3395. //record status
  3396. if(strcmp(status,"Downloaded")==0)
  3397. {
  3398. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3399. }
  3400. else if(strcmp(status,"DownloadFailed")==0)
  3401. {
  3402. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3403. }
  3404. else if(strcmp(status,"Downloading")==0)
  3405. {
  3406. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3407. }
  3408. else if(strcmp(status,"Idle")==0)
  3409. {
  3410. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3411. }
  3412. else if(strcmp(status,"InstallationFailed")==0)
  3413. {
  3414. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3415. }
  3416. else if(strcmp(status,"Installing")==0)
  3417. {
  3418. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3419. }
  3420. else if(strcmp(status,"Installed")==0)
  3421. {
  3422. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3423. }
  3424. return result;
  3425. }
  3426. int sendHeartbeatRequest(int gun_index)
  3427. {
  3428. mtrace();
  3429. int result = FAIL;
  3430. char message[80]={0};
  3431. char guid[37]={0};
  3432. char tempdata[65]={0};
  3433. random_uuid(guid);
  3434. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3435. , MESSAGE_TYPE_CALL
  3436. , guid );
  3437. LWS_Send(message);
  3438. sprintf(tempdata, "Heartbeat,%d", 0);
  3439. 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*/)
  3440. {
  3441. result = PASS;
  3442. }
  3443. return result;
  3444. }
  3445. int sendStartTransactionRequest(int gun_index)
  3446. {
  3447. mtrace();
  3448. int result = FAIL;
  3449. char message[250]={0};
  3450. char guid[37]={0};
  3451. struct timeval tmnow;
  3452. struct tm *tm;
  3453. char buf[28];//, usec_buf[6];
  3454. char tempdata[65]={0};
  3455. int tempIndex = 0;
  3456. DEBUG_INFO("sendStartTransactionRequest...\n");
  3457. gettimeofday(&tmnow, NULL);
  3458. time_t t;
  3459. t = time(NULL);
  3460. /*UTC time and date*/
  3461. tm = gmtime(&t);
  3462. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3463. #if 0 // remove temporally
  3464. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3465. strcat(buf,".");
  3466. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3467. strcat(buf,usec_buf);
  3468. #endif
  3469. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3470. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3471. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3472. // clear StartTransaction Response
  3473. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3474. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3475. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3476. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3477. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3479. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3492. {
  3493. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3494. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3495. }
  3496. }
  3497. }
  3498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3499. {
  3500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3501. {
  3502. tempIndex = ((gun_index==2) ? 1: 0);
  3503. }
  3504. else
  3505. {
  3506. tempIndex = gun_index;
  3507. }
  3508. for (int index = 0; index < CCS_QUANTITY; index++)
  3509. {
  3510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3511. {
  3512. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3513. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3514. }
  3515. }
  3516. }
  3517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3518. {
  3519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3520. {
  3521. tempIndex = ((gun_index==2) ? 1: 0);
  3522. }
  3523. else
  3524. {
  3525. tempIndex = gun_index;
  3526. }
  3527. for (int index = 0; index < GB_QUANTITY; index++)
  3528. {
  3529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3530. {
  3531. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3532. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3533. }
  3534. }
  3535. }
  3536. else if(gunType[gun_index] == GUN_TYPE_DO)
  3537. {
  3538. tempIndex = gun_index;
  3539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3540. {
  3541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3542. {
  3543. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3544. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3545. }
  3546. }
  3547. }
  3548. else
  3549. {
  3550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3551. {
  3552. tempIndex = 2;
  3553. }
  3554. else
  3555. {
  3556. tempIndex = gun_index;
  3557. }
  3558. for (int index = 0; index < AC_QUANTITY; index++)
  3559. {
  3560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3561. {
  3562. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3563. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3564. }
  3565. }
  3566. }
  3567. random_uuid(guid);
  3568. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3569. {
  3570. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3571. , gun_index +1
  3572. , MESSAGE_TYPE_CALL
  3573. , guid
  3574. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3575. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3576. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3577. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3578. }
  3579. else
  3580. {
  3581. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3582. , gun_index +1
  3583. , MESSAGE_TYPE_CALL
  3584. , guid
  3585. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3586. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3587. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3588. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  3589. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3590. }
  3591. #if 1
  3592. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3593. 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*/)
  3594. {
  3595. result = PASS;
  3596. }
  3597. #endif
  3598. strcpy(queuedata, message);
  3599. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3600. OCPP_insert_transaction_msg(YES, queuedata);
  3601. return result;
  3602. }
  3603. int sendStatusNotificationRequest(int gun_index)
  3604. {
  3605. mtrace();
  3606. int result = FAIL;
  3607. char message[600]={0};
  3608. char guid[37];
  3609. int currentStatus = 0;
  3610. struct timeval tmnow;
  3611. struct tm *tm;
  3612. char buf[28];//, usec_buf[6];
  3613. char tempdata[65]={0};
  3614. int tempIndex = 0;
  3615. uint8_t isStateChanged = TRUE;
  3616. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3617. gettimeofday(&tmnow, NULL);
  3618. time_t t;
  3619. t = time(NULL);
  3620. /*UTC time and date*/
  3621. tm = gmtime(&t);
  3622. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3623. #if 0 // remove temporally
  3624. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3625. strcat(buf,".");
  3626. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3627. strcat(buf,usec_buf);
  3628. #endif
  3629. printf("%s",buf);
  3630. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3631. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3632. // it's option
  3633. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  3634. /*
  3635. enum _SYSTEM_STATUS
  3636. {
  3637. S_BOOTING = 0,
  3638. S_IDLE, = 1
  3639. S_AUTHORIZING, =2
  3640. S_REASSIGN_CHECK, =3
  3641. S_REASSIGN, =4
  3642. S_PRECHARGE, =5
  3643. S_PREPARING_FOR_EV, =6
  3644. S_PREPARING_FOR_EVSE, =7
  3645. S_CHARGING, =8
  3646. S_TERMINATING, =9
  3647. S_COMPLETE, =10
  3648. S_ALARM, =11
  3649. S_FAULT =12
  3650. }
  3651. */
  3652. //check Transaction active
  3653. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3654. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((gun_index==2) ? 1: 0);
  3659. }
  3660. else
  3661. {
  3662. tempIndex = gun_index;
  3663. }
  3664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3665. {
  3666. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3667. {
  3668. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3669. {
  3670. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3671. {
  3672. currentStatus = Preparing; //OCPP Status: Preparing
  3673. }
  3674. else
  3675. {
  3676. currentStatus = Available; //OCPP Status: Available
  3677. }
  3678. }
  3679. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3680. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3681. ) //S_PRECHARGE
  3682. {
  3683. currentStatus = Preparing; //OCPP Status: Preparing
  3684. }
  3685. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3686. {
  3687. currentStatus = Charging; //OCPP Status: Charging
  3688. }
  3689. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3690. {
  3691. currentStatus = Finishing; //OCPP Status: Finishing
  3692. }
  3693. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3694. {
  3695. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3696. }
  3697. 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
  3698. {
  3699. currentStatus = Unavailable; //OCPP Status: Unavailable
  3700. }
  3701. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3702. {
  3703. currentStatus = Faulted; //OCPP Status: Faulted
  3704. }
  3705. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3706. {
  3707. currentStatus = Reserved; //OCPP Status: Reserved
  3708. }
  3709. } //end of the same index
  3710. }//end of for CHAdeMO_QUANTITY
  3711. }
  3712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3713. {
  3714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3715. {
  3716. tempIndex = ((gun_index==2) ? 1: 0);
  3717. }
  3718. else
  3719. {
  3720. tempIndex = gun_index;
  3721. }
  3722. for (int index = 0; index < CCS_QUANTITY; index++)
  3723. {
  3724. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3725. {
  3726. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3727. {
  3728. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3729. {
  3730. currentStatus = Preparing; //OCPP Status: Preparing
  3731. }
  3732. else
  3733. {
  3734. currentStatus = Available; //OCPP Status: Available
  3735. }
  3736. }
  3737. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3738. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3739. ) //S_PRECHARGE
  3740. {
  3741. currentStatus = Preparing; //OCPP Status: Preparing
  3742. }
  3743. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3744. {
  3745. currentStatus = Charging; //OCPP Status: Charging
  3746. }
  3747. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3748. {
  3749. currentStatus = Finishing; //OCPP Status: Finishing
  3750. }
  3751. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3752. {
  3753. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3754. }
  3755. 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
  3756. {
  3757. currentStatus = Unavailable; //OCPP Status : Unavailable
  3758. }
  3759. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3760. {
  3761. currentStatus = Faulted; //OCPP Status: Faulted
  3762. }
  3763. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3764. {
  3765. currentStatus = Reserved; //OCPP Status: Reserved
  3766. }
  3767. } //end of the same index
  3768. } // end of for CCS_QUANTITY
  3769. }
  3770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3771. {
  3772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3773. {
  3774. tempIndex = ((gun_index==2) ? 1: 0);
  3775. }
  3776. else
  3777. {
  3778. tempIndex = gun_index;
  3779. }
  3780. for (int index = 0; index < GB_QUANTITY; index++)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3785. {
  3786. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3787. {
  3788. currentStatus = Preparing; //OCPP Status: Preparing
  3789. }
  3790. else
  3791. {
  3792. currentStatus = Available; //OCPP Status: Available
  3793. }
  3794. }
  3795. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3796. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3797. ) //S_PRECHARGE
  3798. {
  3799. currentStatus = Preparing; //OCPP Status: Preparing
  3800. }
  3801. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3802. {
  3803. currentStatus = Charging; //OCPP Status: Charging
  3804. }
  3805. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3806. {
  3807. currentStatus = Finishing; //OCPP Status: Finishing
  3808. }
  3809. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3810. {
  3811. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3812. }
  3813. 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
  3814. {
  3815. currentStatus = Unavailable; //OCPP Status: Unavailable
  3816. }
  3817. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3818. {
  3819. currentStatus = Faulted; //OCPP Status: Faulted
  3820. }
  3821. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3822. {
  3823. currentStatus = Reserved; //OCPP Status: Reserved
  3824. }
  3825. } //end of the same index
  3826. } // end of for GB_QUANTITY
  3827. }
  3828. else if(gunType[gun_index] == GUN_TYPE_DO)
  3829. {
  3830. tempIndex = gun_index;
  3831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3832. {
  3833. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3834. {
  3835. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3836. {
  3837. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3838. {
  3839. currentStatus = Preparing; //OCPP Status: Preparing
  3840. }
  3841. else
  3842. {
  3843. currentStatus = Available; //OCPP Status: Available
  3844. }
  3845. }
  3846. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3847. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3848. ) //S_PRECHARGE
  3849. {
  3850. currentStatus = Preparing; //OCPP Status: Preparing
  3851. }
  3852. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3853. {
  3854. currentStatus = Charging; //OCPP Status: Charging
  3855. }
  3856. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3857. {
  3858. currentStatus = Finishing; //OCPP Status: Finishing
  3859. }
  3860. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3861. {
  3862. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3863. }
  3864. 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
  3865. {
  3866. currentStatus = Unavailable; //OCPP Status: Unavailable
  3867. }
  3868. 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
  3869. {
  3870. currentStatus = Faulted; //OCPP Status: Faulted
  3871. }
  3872. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3873. {
  3874. currentStatus = Reserved; //OCPP Status: Reserved
  3875. }
  3876. } //end of the same index
  3877. }
  3878. }
  3879. else
  3880. {
  3881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3882. {
  3883. tempIndex = 2;
  3884. }
  3885. else
  3886. {
  3887. tempIndex = gun_index;
  3888. }
  3889. for (int index = 0; index < AC_QUANTITY; index++)
  3890. {
  3891. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3892. {
  3893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3894. {
  3895. 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))
  3896. {
  3897. currentStatus = Preparing; //OCPP Status: Preparing
  3898. }
  3899. else
  3900. {
  3901. currentStatus = Available; //OCPP Status: Available
  3902. }
  3903. }
  3904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3905. {
  3906. currentStatus = Preparing; //OCPP Status: Preparing
  3907. }
  3908. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3909. {
  3910. currentStatus = Charging; //OCPP Status: Charging
  3911. }
  3912. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3913. {
  3914. currentStatus = Finishing; //OCPP Status: Finishing
  3915. }
  3916. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3917. {
  3918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3919. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3920. else
  3921. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3922. }
  3923. 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
  3924. {
  3925. currentStatus = Unavailable; //OCPP Status: Unavailable
  3926. }
  3927. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3928. {
  3929. currentStatus = Faulted; //OCPP Status: Faulted
  3930. }
  3931. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3932. {
  3933. currentStatus = Reserved; //OCPP Status: Reserved
  3934. }
  3935. }//end of the same index
  3936. }//end of for AC_QUANTITY
  3937. }
  3938. //it's option
  3939. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3940. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3941. {
  3942. isStateChanged = FALSE;
  3943. }
  3944. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3945. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  3946. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3947. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3948. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  3949. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  3950. random_uuid(guid);
  3951. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3952. , MESSAGE_TYPE_CALL
  3953. , guid
  3954. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  3955. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  3956. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  3957. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  3958. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  3959. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  3960. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  3961. if((server_sign == TRUE) && isStateChanged)
  3962. {
  3963. LWS_Send(message);
  3964. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3965. 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*/)
  3966. {
  3967. //DEBUG_ERROR("statusNotification mapitem pass");
  3968. result = PASS;
  3969. }
  3970. }
  3971. else
  3972. {
  3973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3974. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3975. result = PASS;
  3976. }
  3977. return result;
  3978. }
  3979. int sendStopTransactionRequest(int gun_index)
  3980. {
  3981. mtrace();
  3982. int result = FAIL;
  3983. //char message[1500]={0};
  3984. char guid[37]={0};
  3985. char tempdata[65]={0};
  3986. int tempIndex = 0;
  3987. char TempStopTransaction[256];
  3988. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  3989. //int idx_sample=0;
  3990. DEBUG_INFO("sendStopTransactionRequest \n");
  3991. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3992. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  3993. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3995. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3996. {
  3997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3998. {
  3999. tempIndex = ((gun_index==2) ? 1: 0);
  4000. }
  4001. else
  4002. {
  4003. tempIndex = gun_index;
  4004. }
  4005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4008. {
  4009. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4010. }
  4011. }// END OF CHAdeMO_QUANTITY
  4012. }
  4013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4016. {
  4017. tempIndex = ((gun_index==2) ? 1: 0);
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < CCS_QUANTITY; index++)
  4024. {
  4025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4026. {
  4027. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4028. }
  4029. }// END OF CCS_QUANTITY
  4030. }
  4031. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4032. {
  4033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4034. {
  4035. tempIndex = ((gun_index==2) ? 1: 0);
  4036. }
  4037. else
  4038. {
  4039. tempIndex = gun_index;
  4040. }
  4041. for (int index = 0; index < GB_QUANTITY; index++)
  4042. {
  4043. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4044. {
  4045. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4046. }
  4047. }// END OF GB_QUANTITY
  4048. }
  4049. else if(gunType[gun_index] == GUN_TYPE_DO)
  4050. {
  4051. tempIndex = gun_index;
  4052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4053. {
  4054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4055. {
  4056. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4057. }
  4058. }// END OF GB_QUANTITY
  4059. }
  4060. else
  4061. {
  4062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4063. {
  4064. tempIndex = 2;
  4065. }
  4066. else
  4067. {
  4068. tempIndex = gun_index;
  4069. }
  4070. for (int index = 0; index < AC_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4073. {
  4074. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4075. }
  4076. }// END OF AC_QUANTITY
  4077. }
  4078. //====================================== Stop Transaction Time =====================================================
  4079. struct timeval tmnow;
  4080. struct tm *tm;
  4081. char buf[28];//, usec_buf[6];
  4082. gettimeofday(&tmnow, NULL);
  4083. time_t t;
  4084. t = time(NULL);
  4085. /*UTC time and date*/
  4086. tm = gmtime(&t);
  4087. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4089. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4090. random_uuid(guid);
  4091. /***********************************transactionData******************************************************/
  4092. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4094. //=================================
  4095. // Transaction_Begin
  4096. //=================================
  4097. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4098. {
  4099. //============================================ Energy.Active.Import.Interval ================================
  4100. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4105. 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))
  4106. {
  4107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4108. }
  4109. else
  4110. {
  4111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4112. }
  4113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4115. }
  4116. //=================================
  4117. // Transaction_End
  4118. //=================================
  4119. // ================================= Current.Import L1 ===============================================
  4120. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4121. {
  4122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4138. }
  4139. }// End of for CHAdeMO_QUANTITY
  4140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < CCS_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4157. }
  4158. }// End of for CCS_QUANTITY
  4159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4164. {
  4165. tempIndex = ((gun_index==2) ? 1: 0);
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < GB_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4176. }
  4177. }// End of for GB_QUANTITY
  4178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4179. }
  4180. else if(gunType[gun_index] == GUN_TYPE_DO)
  4181. {
  4182. tempIndex = gun_index;
  4183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4186. {
  4187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4188. }
  4189. }
  4190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4191. }
  4192. else
  4193. {
  4194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4195. {
  4196. tempIndex = 2;
  4197. }
  4198. else
  4199. {
  4200. tempIndex = gun_index;
  4201. }
  4202. for (int index = 0; index < AC_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4205. {
  4206. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4207. }
  4208. }// End of for AC_QUANTITY
  4209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4210. }
  4211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4216. }
  4217. // ================================= Energy.Active.Import.Interval ==============================================
  4218. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4219. {
  4220. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4236. }
  4237. }// END OF CHAdeMO_QUANTITY
  4238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4239. }
  4240. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < CCS_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4255. }
  4256. }// END OF CCS_QUANTITY
  4257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4260. {
  4261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4262. {
  4263. tempIndex = ((gun_index==2) ? 1: 0);
  4264. }
  4265. else
  4266. {
  4267. tempIndex = gun_index;
  4268. }
  4269. for (int index = 0; index < GB_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4272. {
  4273. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4274. }
  4275. }// END OF GB_QUANTITY
  4276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4277. }
  4278. else if(gunType[gun_index] == GUN_TYPE_DO)
  4279. {
  4280. tempIndex = gun_index;
  4281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4284. {
  4285. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4286. }
  4287. }
  4288. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4289. }
  4290. else
  4291. {
  4292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4293. {
  4294. tempIndex = 2;
  4295. }
  4296. else
  4297. {
  4298. tempIndex = gun_index;
  4299. }
  4300. for (int index = 0; index < AC_QUANTITY; index++)
  4301. {
  4302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4303. {
  4304. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4305. }
  4306. }// END OF AC_QUANTITY
  4307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4308. }
  4309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4314. }
  4315. //=================================== Power.Active.Import ==================================================
  4316. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4317. {
  4318. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4319. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4334. }
  4335. } // End for CHAdeMO_QUANTITY
  4336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < CCS_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4353. }
  4354. } // END for CCS_QUANTITY
  4355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < GB_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4372. }
  4373. }// END for GB_QUANTITY
  4374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4375. }
  4376. else if(gunType[gun_index] == GUN_TYPE_DO)
  4377. {
  4378. tempIndex = gun_index;
  4379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4384. }
  4385. }
  4386. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4387. }
  4388. else
  4389. {
  4390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4391. {
  4392. tempIndex = 2;
  4393. }
  4394. else
  4395. {
  4396. tempIndex = gun_index;
  4397. }
  4398. for (int index = 0; index < AC_QUANTITY; index++)
  4399. {
  4400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4401. {
  4402. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4403. }
  4404. } // END for AC_QUANTITY
  4405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4406. }
  4407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4412. }
  4413. //============================ Voltage L1 ====================================
  4414. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4415. {
  4416. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4417. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4432. }
  4433. } // END OF FOR CHAdeMO_QUANTITY
  4434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < CCS_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4451. }
  4452. } // END OF FOR CCS_QUANTITY
  4453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4456. {
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4458. {
  4459. tempIndex = ((gun_index==2) ? 1: 0);
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. for (int index = 0; index < GB_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4468. {
  4469. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4470. }
  4471. } // END OF FOR GB_QUANTITY
  4472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4473. }
  4474. else if(gunType[gun_index] == GUN_TYPE_DO)
  4475. {
  4476. tempIndex = gun_index;
  4477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4480. {
  4481. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4482. }
  4483. }
  4484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4485. }
  4486. else
  4487. {
  4488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4489. {
  4490. tempIndex = 2;
  4491. }
  4492. else
  4493. {
  4494. tempIndex = gun_index;
  4495. }
  4496. for (int index = 0; index < AC_QUANTITY; index++)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4499. {
  4500. 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
  4501. }
  4502. } // END OF FOR AC_QUANTITY
  4503. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4504. }
  4505. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4510. }
  4511. //====================== End SoC ================================
  4512. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4513. {
  4514. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4515. 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))
  4516. {
  4517. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4518. {
  4519. tempIndex = ((gun_index==2) ? 1: 0);
  4520. }
  4521. else
  4522. {
  4523. tempIndex = gun_index;
  4524. }
  4525. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4526. {
  4527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4528. {
  4529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4530. {
  4531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4532. }
  4533. }
  4534. }
  4535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4536. {
  4537. for (int index = 0; index < CCS_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4542. }
  4543. }
  4544. }
  4545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4546. {
  4547. for (int index = 0; index < GB_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4550. {
  4551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4552. }
  4553. }
  4554. }
  4555. else if(gunType[gun_index] == GUN_TYPE_DO)
  4556. {
  4557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4558. {
  4559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4560. {
  4561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4562. }
  4563. }
  4564. }
  4565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4571. } // END FOR DC CASE
  4572. }
  4573. // ================================= Current.Import L2 ===============================================
  4574. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4575. {
  4576. // AC 3 phse L2 current
  4577. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4578. {
  4579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4580. {
  4581. tempIndex = 2;
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. for (int index = 0; index < AC_QUANTITY; index++)
  4588. {
  4589. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4590. {
  4591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4592. }
  4593. }// End of for AC_QUANTITY
  4594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4595. }
  4596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4601. }
  4602. // ================================= Current.Import L3 ===============================================
  4603. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4604. {
  4605. // AC 3 phse L3 current
  4606. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4607. {
  4608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4609. {
  4610. tempIndex = 2;
  4611. }
  4612. else
  4613. {
  4614. tempIndex = gun_index;
  4615. }
  4616. for (int index = 0; index < AC_QUANTITY; index++)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4619. {
  4620. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4621. }
  4622. }// End of for AC_QUANTITY
  4623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4624. }
  4625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4630. }
  4631. //============================ Voltage L2 ====================================
  4632. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4633. {
  4634. // AC 3 phse L2 voltage
  4635. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4636. {
  4637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4638. {
  4639. tempIndex = 2;
  4640. }
  4641. else
  4642. {
  4643. tempIndex = gun_index;
  4644. }
  4645. for (int index = 0; index < AC_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4648. {
  4649. 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
  4650. }
  4651. } // END OF FOR AC_QUANTITY
  4652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4653. }
  4654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4659. }
  4660. //============================ Voltage L3 ====================================
  4661. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4662. {
  4663. // AC 3 phse L3 voltage
  4664. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4665. {
  4666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4667. {
  4668. tempIndex = 2;
  4669. }
  4670. else
  4671. {
  4672. tempIndex = gun_index;
  4673. }
  4674. for (int index = 0; index < AC_QUANTITY; index++)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4677. {
  4678. 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
  4679. }
  4680. } // END OF FOR AC_QUANTITY
  4681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4682. }
  4683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4688. }
  4689. //====================== Start SoC ================================
  4690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4691. {
  4692. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4693. 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))
  4694. {
  4695. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4696. {
  4697. tempIndex = ((gun_index==2) ? 1: 0);
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4704. {
  4705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4706. {
  4707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4708. {
  4709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4710. }
  4711. }
  4712. }
  4713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4714. {
  4715. for (int index = 0; index < CCS_QUANTITY; index++)
  4716. {
  4717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4718. {
  4719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4720. }
  4721. }
  4722. }
  4723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4724. {
  4725. for (int index = 0; index < GB_QUANTITY; index++)
  4726. {
  4727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4728. {
  4729. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4730. }
  4731. }
  4732. }
  4733. else if(gunType[gun_index] == GUN_TYPE_DO)
  4734. {
  4735. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4736. {
  4737. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4738. {
  4739. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4740. }
  4741. }
  4742. }
  4743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4749. } // END FOR DC CASE
  4750. }
  4751. //================================================ Message create ====================================================
  4752. json_object *StopTransaction = json_object_new_object();
  4753. json_object *transactionDatas = json_object_new_array();
  4754. json_object *sampledValues = json_object_new_array();
  4755. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  4756. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  4757. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  4758. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  4759. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  4760. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  4761. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  4762. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  4763. {
  4764. json_object *transactionData = json_object_new_object();
  4765. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4766. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4767. {
  4768. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4769. {
  4770. json_object *sampledValue = json_object_new_object();
  4771. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4772. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4773. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4774. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4775. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4776. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4777. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4778. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4779. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4780. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4781. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4782. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4783. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4784. json_object_array_add(sampledValues, sampledValue);
  4785. }
  4786. }
  4787. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4788. json_object_array_add(transactionDatas, transactionData);
  4789. }
  4790. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4791. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4792. ,MESSAGE_TYPE_CALL
  4793. ,guid
  4794. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4795. json_object_put(StopTransaction);
  4796. #if 1 // for TempStopTransaction
  4797. //Delete TempStopTransaction
  4798. if((access(TempStopTransaction,F_OK))!=-1)
  4799. {
  4800. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4801. }
  4802. #endif
  4803. #if 1
  4804. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4805. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4806. {
  4807. result = PASS;
  4808. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4809. }
  4810. #endif
  4811. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4812. OCPP_insert_transaction_msg(NO, queuedata);
  4813. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4814. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  4815. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  4816. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4817. {
  4818. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  4819. }
  4820. //for test
  4821. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4822. return result;
  4823. }
  4824. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4825. {
  4826. mtrace();
  4827. int result = FAIL;
  4828. char guid[37]={0};
  4829. char tempdata[65]={0};
  4830. int tempIndex = 0;
  4831. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4832. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4833. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4834. //set value
  4835. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4836. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4837. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  4838. -1);
  4839. random_uuid(guid);
  4840. //UTC Date time
  4841. struct timeval tmnow;
  4842. struct tm *tm;
  4843. char buf[28];//, usec_buf[6];
  4844. gettimeofday(&tmnow, NULL);
  4845. time_t t;
  4846. t = time(NULL);
  4847. /*UTC time and date*/
  4848. tm = gmtime(&t);
  4849. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4851. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4852. //********************************(1)Current.Import L1************************************************/
  4853. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4854. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4855. (dataType == ReadingContext_Trigger))
  4856. {
  4857. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4858. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < CCS_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4890. {
  4891. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4892. }
  4893. }
  4894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4899. {
  4900. tempIndex = ((gun_index==2) ? 1: 0);
  4901. }
  4902. else
  4903. {
  4904. tempIndex = gun_index;
  4905. }
  4906. for (int index = 0; index < GB_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4909. {
  4910. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4911. }
  4912. }
  4913. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4914. }
  4915. else if(gunType[gun_index] == GUN_TYPE_DO)
  4916. {
  4917. tempIndex = gun_index;
  4918. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4923. }
  4924. }
  4925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4926. }
  4927. else
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4930. {
  4931. tempIndex = 2;
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < AC_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4942. }
  4943. }
  4944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4945. }
  4946. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4950. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4951. }
  4952. //********************************(2)Energy.Active.Import.Register ************************************************/
  4953. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4954. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4955. (dataType == ReadingContext_Trigger))
  4956. {
  4957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4958. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4961. {
  4962. tempIndex = ((gun_index==2) ? 1: 0);
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4980. {
  4981. tempIndex = ((gun_index==2) ? 1: 0);
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < CCS_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4995. }
  4996. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4997. {
  4998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4999. {
  5000. tempIndex = ((gun_index==2) ? 1: 0);
  5001. }
  5002. else
  5003. {
  5004. tempIndex = gun_index;
  5005. }
  5006. for (int index = 0; index < GB_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5011. }
  5012. }
  5013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5014. }
  5015. else if(gunType[gun_index] == GUN_TYPE_DO)
  5016. {
  5017. tempIndex = gun_index;
  5018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5023. }
  5024. }
  5025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5026. }
  5027. else
  5028. {
  5029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5030. {
  5031. tempIndex = 2;
  5032. }
  5033. else
  5034. {
  5035. tempIndex = gun_index;
  5036. }
  5037. for (int index = 0; index < AC_QUANTITY; index++)
  5038. {
  5039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5040. {
  5041. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5042. }
  5043. }
  5044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5045. }
  5046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5051. }
  5052. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5053. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5054. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5055. (dataType == ReadingContext_Trigger))
  5056. {
  5057. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5073. }
  5074. } // END OF FOR CHAdeMO_QUANTITY
  5075. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < CCS_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5092. }
  5093. } // END OF CCS_QUANTITY
  5094. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5097. {
  5098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5099. {
  5100. tempIndex = ((gun_index==2) ? 1: 0);
  5101. }
  5102. else
  5103. {
  5104. tempIndex = gun_index;
  5105. }
  5106. for (int index = 0; index < GB_QUANTITY; index++)
  5107. {
  5108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5109. {
  5110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5111. }
  5112. } // END OF GB_QUANTITY
  5113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5114. }
  5115. else if(gunType[gun_index] == GUN_TYPE_DO)
  5116. {
  5117. tempIndex = gun_index;
  5118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5123. }
  5124. }
  5125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5126. }
  5127. else
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5130. {
  5131. tempIndex = 2;
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < AC_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5142. }
  5143. }
  5144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5145. }
  5146. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5150. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5151. }
  5152. //********************************(4)Power.Active.Import************************************************/
  5153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5155. (dataType == ReadingContext_Trigger))
  5156. {
  5157. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5173. }
  5174. } // END OF FOR
  5175. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5192. }
  5193. }
  5194. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < GB_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5209. {
  5210. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5211. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5212. }
  5213. }
  5214. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5215. }
  5216. else if(gunType[gun_index] == GUN_TYPE_DO)
  5217. {
  5218. tempIndex = gun_index;
  5219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5220. {
  5221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5222. {
  5223. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5224. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5225. }
  5226. }
  5227. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5228. }
  5229. else
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5232. {
  5233. tempIndex = 2;
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < AC_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5242. {
  5243. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5244. }
  5245. }
  5246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5247. }
  5248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5250. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5251. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5252. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5253. }
  5254. //***********************************************(5)VOLTAGE L1******************************************************/
  5255. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5256. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5257. (dataType == ReadingContext_Trigger))
  5258. {
  5259. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5260. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5275. }
  5276. }
  5277. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5282. {
  5283. tempIndex = ((gun_index==2) ? 1: 0);
  5284. }
  5285. else
  5286. {
  5287. tempIndex = gun_index;
  5288. }
  5289. for (int index = 0; index < CCS_QUANTITY; index++)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5292. {
  5293. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5294. }
  5295. }
  5296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5297. }
  5298. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5299. {
  5300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5301. {
  5302. tempIndex = ((gun_index==2) ? 1: 0);
  5303. }
  5304. else
  5305. {
  5306. tempIndex = gun_index;
  5307. }
  5308. for (int index = 0; index < GB_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5313. }
  5314. }
  5315. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5316. }
  5317. else if(gunType[gun_index] == GUN_TYPE_DO)
  5318. {
  5319. tempIndex = gun_index;
  5320. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5325. }
  5326. }
  5327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5328. }
  5329. else
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5332. {
  5333. tempIndex = 2;
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < AC_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5342. {
  5343. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5344. }
  5345. }
  5346. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5347. }
  5348. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5353. }
  5354. //***********************************************(6)SOC******************************************************/
  5355. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5356. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5357. (dataType == ReadingContext_Trigger))
  5358. {
  5359. 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))
  5360. {
  5361. //idx_sample=5;
  5362. //sampledValue = NULL;
  5363. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5364. {
  5365. tempIndex = ((gun_index==2) ? 1: 0);
  5366. }
  5367. else
  5368. {
  5369. tempIndex = gun_index;
  5370. }
  5371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5372. {
  5373. //tempIndex = ((gun_index==2) ? 1: 0);
  5374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5375. {
  5376. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5377. {
  5378. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5379. }
  5380. }
  5381. }
  5382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5383. {
  5384. //tempIndex = ((gun_index==2) ? 1: 0);
  5385. for (int index = 0; index < CCS_QUANTITY; index++)
  5386. {
  5387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5388. {
  5389. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5390. }
  5391. }
  5392. }
  5393. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5394. {
  5395. //tempIndex = ((gun_index==2) ? 1: 0);
  5396. for (int index = 0; index < GB_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5399. {
  5400. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5401. }
  5402. }
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_DO)
  5405. {
  5406. //tempIndex = ((gun_index==2) ? 1: 0);
  5407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5410. {
  5411. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5412. }
  5413. }
  5414. }
  5415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5417. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5421. }
  5422. }
  5423. //********************************(7)Current.Import L2************************************************/
  5424. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5425. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5426. (dataType == ReadingContext_Trigger))
  5427. {
  5428. // Only for AC 3 phase
  5429. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5432. {
  5433. tempIndex = 2;
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5442. {
  5443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5444. }
  5445. }
  5446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5447. }
  5448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5453. }
  5454. //********************************(8)Current.Import L3************************************************/
  5455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5457. (dataType == ReadingContext_Trigger))
  5458. {
  5459. // Only for AC 3 phase
  5460. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5461. {
  5462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5463. {
  5464. tempIndex = 2;
  5465. }
  5466. else
  5467. {
  5468. tempIndex = gun_index;
  5469. }
  5470. for (int index = 0; index < AC_QUANTITY; index++)
  5471. {
  5472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5473. {
  5474. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5475. }
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5478. }
  5479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5484. }
  5485. //***********************************************(9)VOLTAGE L2******************************************************/
  5486. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5487. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5488. (dataType == ReadingContext_Trigger))
  5489. {
  5490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5493. {
  5494. tempIndex = 2;
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < AC_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5503. {
  5504. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5505. }
  5506. }
  5507. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5508. }
  5509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5514. }
  5515. //***********************************************(10)VOLTAGE L3******************************************************/
  5516. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5517. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5518. (dataType == ReadingContext_Trigger))
  5519. {
  5520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5521. {
  5522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5523. {
  5524. tempIndex = 2;
  5525. }
  5526. else
  5527. {
  5528. tempIndex = gun_index;
  5529. }
  5530. for (int index = 0; index < AC_QUANTITY; index++)
  5531. {
  5532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5533. {
  5534. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5538. }
  5539. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5540. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5541. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5542. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5544. }
  5545. // Message create ====================================================================================================
  5546. if(TRUE)
  5547. {
  5548. json_object *MeterValueReq = json_object_new_object();
  5549. json_object *MeterValues = json_object_new_array();
  5550. json_object *sampledValues = json_object_new_array();
  5551. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  5552. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  5553. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  5554. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  5555. {
  5556. json_object *MeterValue = json_object_new_object();
  5557. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5558. {
  5559. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5560. {
  5561. json_object *sampledValue = json_object_new_object();
  5562. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5563. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5564. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5565. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5566. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5567. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5568. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5569. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5570. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5571. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5572. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5573. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5574. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5575. json_object_array_add(sampledValues, sampledValue);
  5576. }
  5577. }
  5578. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5579. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5580. json_object_array_add(MeterValues, MeterValue);
  5581. }
  5582. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5583. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5584. ,gun_index + 1
  5585. ,MESSAGE_TYPE_CALL
  5586. ,guid
  5587. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5588. json_object_put(MeterValueReq);
  5589. }
  5590. // Put request guid to hash map
  5591. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5592. 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*/)
  5593. {
  5594. result = PASS;
  5595. //DEBUG_INFO("MeterValues mapitem pass\n");
  5596. }
  5597. if((dataType != ReadingContext_Trigger) &&
  5598. (dataType != ReadingContext_Sample_Clock) &&
  5599. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  5600. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5601. else
  5602. {
  5603. if(FirstHeartBeat)
  5604. LWS_Send(queuedata +2);
  5605. }
  5606. return result;
  5607. }
  5608. int sendLogStatusNotificationRequest(char *status)
  5609. {
  5610. mtrace();
  5611. int result = PASS;
  5612. char message[4096]={0};
  5613. char guid[37]={0};
  5614. char tempdata[128]={0};
  5615. json_object *LogStatusNotification = json_object_new_object();
  5616. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5617. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  5618. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  5619. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  5620. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  5621. random_uuid(guid);
  5622. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5623. json_object_put(LogStatusNotification);
  5624. LWS_Send(message);
  5625. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5626. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5627. {
  5628. result = PASS;
  5629. }
  5630. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  5631. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  5632. return result;
  5633. }
  5634. int sendSecurityEventNotificationRequest()
  5635. {
  5636. mtrace();
  5637. int result = PASS;
  5638. char message[4096]={0};
  5639. char guid[37]={0};
  5640. char tempdata[128]={0};
  5641. json_object *SecurityEventNotification = json_object_new_object();
  5642. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5643. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  5644. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  5645. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  5646. random_uuid(guid);
  5647. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5648. json_object_put(SecurityEventNotification);
  5649. LWS_Send(message);
  5650. sprintf(tempdata, "SecurityEventNotification,0");
  5651. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5652. {
  5653. result = PASS;
  5654. }
  5655. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  5656. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  5657. return result;
  5658. }
  5659. int sendSignCertificateRequest()
  5660. {
  5661. mtrace();
  5662. int result = PASS;
  5663. char message[4096]={0};
  5664. char guid[37]={0};
  5665. char tempdata[128]={0};
  5666. json_object *SignCertificate = json_object_new_object();
  5667. DEBUG_INFO("sendSignCertificateRequest...\n");
  5668. // Read csr file content
  5669. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  5670. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  5671. char *line = NULL;
  5672. size_t len = 0;
  5673. while(getline(&line, &len, fp) != -1)
  5674. {
  5675. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5676. {
  5677. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  5678. }
  5679. }
  5680. fclose(fp);
  5681. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  5682. random_uuid(guid);
  5683. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5684. json_object_put(SignCertificate);
  5685. LWS_Send(message);
  5686. sprintf(tempdata, "SignCertificate,0");
  5687. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5688. {
  5689. result = PASS;
  5690. }
  5691. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  5692. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  5693. return result;
  5694. }
  5695. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5696. {
  5697. mtrace();
  5698. int result = PASS;
  5699. char message[110]={0};
  5700. char guid[37]={0};
  5701. char tempdata[65]={0};
  5702. json_object *FirmwareStatusNotification = json_object_new_object();
  5703. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5704. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5705. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  5706. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  5707. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  5708. random_uuid(guid);
  5709. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5710. json_object_put(FirmwareStatusNotification);
  5711. LWS_Send(message);
  5712. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5713. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5714. {
  5715. result = PASS;
  5716. }
  5717. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5718. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5719. return result;
  5720. }
  5721. //==========================================
  5722. // send confirm routine
  5723. //==========================================
  5724. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5725. {
  5726. mtrace();
  5727. int result = FAIL;
  5728. char message[100]={0};
  5729. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5730. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5731. LWS_Send(message);
  5732. result = TRUE;
  5733. return result;
  5734. }
  5735. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5736. {
  5737. mtrace();
  5738. int result = FAIL;
  5739. char message[100]={0};
  5740. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5741. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5742. LWS_Send(message);
  5743. result = TRUE;
  5744. return result;
  5745. }
  5746. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5747. {
  5748. mtrace();
  5749. int result = FAIL;
  5750. char message[100]={0};
  5751. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5753. LWS_Send(message);
  5754. result = TRUE;
  5755. return result;
  5756. }
  5757. int sendClearCacheConfirmation(char *uuid,char *payload)
  5758. {
  5759. mtrace();
  5760. int result = FAIL;
  5761. char message[500]={0};
  5762. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5763. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5764. LWS_Send(message);
  5765. return result;
  5766. }
  5767. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5768. {
  5769. mtrace();
  5770. int result = FAIL;
  5771. char message[500]={0};
  5772. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5773. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5774. LWS_Send(message);
  5775. return result;
  5776. }
  5777. int sendDataTransferConfirmation(char *uuid,char *payload)
  5778. {
  5779. mtrace();
  5780. char statusStr[20]={0};
  5781. char dataStr[10]={0};
  5782. char sstr[20]={0};
  5783. int c = 0;
  5784. char *loc;
  5785. int result = FAIL;
  5786. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5787. /**********************status**************************/
  5788. loc = strstr(payload, "status");
  5789. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5790. c = 0;
  5791. while (loc[3+strlen("status")+c] != '\"')
  5792. {
  5793. sstr[c] = loc[3+strlen("status")+c];
  5794. c++;
  5795. }
  5796. sstr[c] = '\0';
  5797. strcpy(statusStr, sstr);
  5798. /**********************data**************************/
  5799. loc = strstr(payload, "data");
  5800. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5801. c = 0;
  5802. while (loc[3+strlen("data")+c] != '\"')
  5803. {
  5804. sstr[c] = loc[3+strlen("data")+c];
  5805. c++;
  5806. }
  5807. sstr[c] = '\0';
  5808. strcpy(dataStr, sstr);
  5809. return result;
  5810. }
  5811. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5812. {
  5813. mtrace();
  5814. int result = FAIL;
  5815. char message[1000]={0};
  5816. int CompositeScheduleIndex = 0;
  5817. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5818. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5819. if(nPeriod == 0)
  5820. {
  5821. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5822. {
  5823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5824. ,MESSAGE_TYPE_CALLRESULT
  5825. ,uuid
  5826. ,payload
  5827. ,connectorIdInt);
  5828. }
  5829. else
  5830. {
  5831. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5832. ,MESSAGE_TYPE_CALLRESULT
  5833. ,uuid
  5834. ,payload
  5835. ,connectorIdInt
  5836. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5837. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5838. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5839. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5840. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5841. }
  5842. }
  5843. else
  5844. {
  5845. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5846. ,MESSAGE_TYPE_CALLRESULT
  5847. ,uuid
  5848. ,payload
  5849. ,connectorIdInt
  5850. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5851. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5852. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5853. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5854. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5855. {
  5856. if (idx_sample == 0)
  5857. {
  5858. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5859. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5860. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5861. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5862. }
  5863. else
  5864. {
  5865. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5866. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5867. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5868. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5869. }
  5870. }
  5871. sprintf(message + strlen(message), "]}}]");
  5872. }
  5873. LWS_Send(message);
  5874. result = TRUE;
  5875. return result;
  5876. }
  5877. int sendGetConfigurationConfirmation(char *uuid)
  5878. {
  5879. mtrace();
  5880. int result = FAIL;
  5881. int MaxKeySupported = 0;
  5882. int sentConfigurationNumber= 0;
  5883. int sentunConfigurationNumber= 0;
  5884. char message[4000]={0};
  5885. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5886. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5887. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5888. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5889. ,MESSAGE_TYPE_CALLRESULT
  5890. ,uuid );
  5891. //configuration key
  5892. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5893. {
  5894. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5895. {
  5896. if (sentConfigurationNumber == 0)
  5897. {
  5898. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5899. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5900. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5901. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5902. }
  5903. else
  5904. {
  5905. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5906. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5907. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5908. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5909. }
  5910. sentConfigurationNumber = sentConfigurationNumber + 1;
  5911. }
  5912. }
  5913. sprintf(message + strlen(message), "]");
  5914. if(UnknownKeynum != 0)
  5915. {
  5916. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5917. //unkown key
  5918. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5919. {
  5920. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5921. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5922. if(sentunConfigurationNumber == 0)
  5923. {
  5924. sprintf(message + strlen(message), "\"%s\""
  5925. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5926. }
  5927. else
  5928. {
  5929. sprintf(message + strlen(message), ",\"%s\""
  5930. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5931. }
  5932. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5933. }
  5934. sprintf(message + strlen(message), "]");
  5935. }
  5936. sprintf(message + strlen(message), "}]");
  5937. LWS_Send(message);
  5938. return result;
  5939. }
  5940. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5941. {
  5942. mtrace();
  5943. int result = FAIL;
  5944. char message[400]={0};
  5945. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5946. if(strcmp(payload,"")==0)
  5947. {
  5948. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5949. }
  5950. else
  5951. {
  5952. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5953. }
  5954. LWS_Send(message);
  5955. result = TRUE;
  5956. return result;
  5957. }
  5958. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5959. {
  5960. mtrace();
  5961. int result = FAIL;
  5962. char message[80]={0};
  5963. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5964. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  5965. LWS_Send(message);
  5966. result = TRUE;
  5967. return result;
  5968. }
  5969. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5970. {
  5971. mtrace();
  5972. int result = FAIL;
  5973. char message[80]={0};
  5974. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5976. LWS_Send(message);
  5977. result = TRUE;
  5978. return result;
  5979. }
  5980. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5981. {
  5982. mtrace();
  5983. int result = FAIL;
  5984. char message[80]={0};
  5985. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5987. LWS_Send(message);
  5988. result = TRUE;
  5989. return result;
  5990. }
  5991. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5992. {
  5993. mtrace();
  5994. int result = FAIL;
  5995. char message[80]={0};
  5996. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5997. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5999. LWS_Send(message);
  6000. result = TRUE;
  6001. return result;
  6002. }
  6003. int sendResetConfirmation(char *uuid,char *payload)
  6004. {
  6005. mtrace();
  6006. int result = FAIL;
  6007. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6008. char message[80]={0};
  6009. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6011. LWS_Send(message);
  6012. result = TRUE;
  6013. return result;
  6014. }
  6015. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6016. {
  6017. mtrace();
  6018. int result = FAIL;
  6019. char message[500]={0};
  6020. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6021. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6022. LWS_Send(message);
  6023. result = TRUE;
  6024. return result;
  6025. }
  6026. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6027. {
  6028. mtrace();
  6029. int result = FAIL;
  6030. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6031. char message[80]={0};
  6032. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6033. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6034. LWS_Send(message);
  6035. result = TRUE;
  6036. return result;
  6037. }
  6038. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6039. {
  6040. mtrace();
  6041. int result = FAIL;
  6042. char message[80]={0};
  6043. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6044. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6045. LWS_Send(message);
  6046. result = TRUE;
  6047. return result;
  6048. }
  6049. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6050. {
  6051. mtrace();
  6052. int result = FAIL;
  6053. char message[80]={0};
  6054. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6055. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6056. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6057. LWS_Send(message);
  6058. result = TRUE;
  6059. return result;
  6060. }
  6061. int sendUpdateFirmwareConfirmation(char *uuid)
  6062. {
  6063. mtrace();
  6064. int result = FAIL;
  6065. char message[60]={0};
  6066. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6067. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6068. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6069. LWS_Send(message);
  6070. result = TRUE;
  6071. return result;
  6072. }
  6073. int sendCertificateSignedConfirmation(char *uuid)
  6074. {
  6075. mtrace();
  6076. int result = PASS;
  6077. char message[4096]={0};
  6078. json_object *CertificateSigned = json_object_new_object();
  6079. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6080. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6081. sprintf(message,"[%d,\"%s\",%s]"
  6082. ,MESSAGE_TYPE_CALLRESULT
  6083. ,uuid
  6084. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6085. json_object_put(CertificateSigned);
  6086. LWS_Send(message);
  6087. return result;
  6088. }
  6089. int sendDeleteCertificateConfirmation(char *uuid)
  6090. {
  6091. mtrace();
  6092. int result = PASS;
  6093. char message[4096]={0};
  6094. json_object *DeleteCertificate = json_object_new_object();
  6095. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6096. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6097. sprintf(message,"[%d,\"%s\",%s]"
  6098. ,MESSAGE_TYPE_CALLRESULT
  6099. ,uuid
  6100. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6101. json_object_put(DeleteCertificate);
  6102. LWS_Send(message);
  6103. return result;
  6104. }
  6105. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6106. {
  6107. mtrace();
  6108. int result = PASS;
  6109. char message[4096]={0};
  6110. json_object *ExtendedTriggerMessage = json_object_new_object();
  6111. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6112. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6113. sprintf(message,"[%d,\"%s\",%s]"
  6114. ,MESSAGE_TYPE_CALLRESULT
  6115. ,uuid
  6116. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6117. json_object_put(ExtendedTriggerMessage);
  6118. LWS_Send(message);
  6119. return result;
  6120. }
  6121. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6122. {
  6123. mtrace();
  6124. int result = PASS;
  6125. char message[4096]={0};
  6126. json_object *GetInstalledCertificateIds = json_object_new_object();
  6127. json_object *certificateHashDataDatas = json_object_new_array();
  6128. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6129. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6130. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6131. {
  6132. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6133. {
  6134. json_object *certificateHashData = json_object_new_object();
  6135. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6136. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6137. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6138. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6139. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6140. }
  6141. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6142. }
  6143. else
  6144. {
  6145. json_object_put(certificateHashDataDatas);
  6146. }
  6147. sprintf(message,"[%d,\"%s\",%s]"
  6148. ,MESSAGE_TYPE_CALLRESULT
  6149. ,uuid
  6150. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6151. json_object_put(GetInstalledCertificateIds);
  6152. LWS_Send(message);
  6153. return result;
  6154. }
  6155. int sendGetLogConfirmation(char *uuid)
  6156. {
  6157. mtrace();
  6158. int result = PASS;
  6159. char message[4096]={0};
  6160. json_object *GetLog = json_object_new_object();
  6161. DEBUG_INFO("sendGetLogConfirmation...\n");
  6162. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6163. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6164. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6165. sprintf(message,"[%d,\"%s\",%s]"
  6166. ,MESSAGE_TYPE_CALLRESULT
  6167. ,uuid
  6168. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6169. json_object_put(GetLog);
  6170. LWS_Send(message);
  6171. return result;
  6172. }
  6173. int sendInstallCertificateConfirmation(char *uuid)
  6174. {
  6175. mtrace();
  6176. int result = PASS;
  6177. char message[4096]={0};
  6178. json_object *InstallCertificate = json_object_new_object();
  6179. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6180. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6181. sprintf(message,"[%d,\"%s\",%s]"
  6182. ,MESSAGE_TYPE_CALLRESULT
  6183. ,uuid
  6184. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6185. json_object_put(InstallCertificate);
  6186. LWS_Send(message);
  6187. return result;
  6188. }
  6189. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6190. {
  6191. mtrace();
  6192. int result = PASS;
  6193. char message[4096]={0};
  6194. json_object *SignedUpdateFirmware = json_object_new_object();
  6195. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6196. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6197. sprintf(message,"[%d,\"%s\",%s]"
  6198. ,MESSAGE_TYPE_CALLRESULT
  6199. ,uuid
  6200. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6201. json_object_put(SignedUpdateFirmware);
  6202. LWS_Send(message);
  6203. return result;
  6204. }
  6205. int sendUnknownConfirmation(char *uuid)
  6206. {
  6207. mtrace();
  6208. int result = PASS;
  6209. char message[256]={0};
  6210. DEBUG_INFO("sendUnknownConfirmation...\n");
  6211. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6212. LWS_Send(message);
  6213. return result;
  6214. }
  6215. //==========================================
  6216. // Handle server request routine Start
  6217. //==========================================
  6218. int handleCancelReservationRequest(char *uuid, char *payload)
  6219. {
  6220. mtrace();
  6221. int result = FAIL;
  6222. int gunNO = 0;
  6223. int reservationIdInt = -1;
  6224. char comfirmstr[20];
  6225. DEBUG_INFO("handleCancelReservationRequest...\n");
  6226. json_object *CancelReservation;
  6227. CancelReservation = json_tokener_parse(payload);
  6228. if(!is_error(CancelReservation))
  6229. {
  6230. // Required data
  6231. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6232. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6233. }
  6234. json_object_put(CancelReservation);
  6235. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6236. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6237. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6238. if(reservationIdInt != -1)
  6239. {
  6240. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6241. //check Transaction active
  6242. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6244. {
  6245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6246. {
  6247. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6248. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6249. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6250. {
  6251. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6252. }
  6253. else
  6254. {
  6255. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6256. }
  6257. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6258. goto end;
  6259. }
  6260. }
  6261. for (int index = 0; index < CCS_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6264. {
  6265. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6266. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6267. if(gunType[2] == GUN_TYPE_CCS)
  6268. {
  6269. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6270. }
  6271. else
  6272. {
  6273. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6274. }
  6275. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6276. goto end;
  6277. }
  6278. }
  6279. for (int index = 0; index < GB_QUANTITY; index++)
  6280. {
  6281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6282. {
  6283. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6284. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6285. if(gunType[2] == GUN_TYPE_GBT)
  6286. {
  6287. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6288. }
  6289. else
  6290. {
  6291. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6292. }
  6293. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6294. goto end;
  6295. }
  6296. }
  6297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6298. {
  6299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6300. {
  6301. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6302. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6303. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6304. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6305. goto end;
  6306. }
  6307. }
  6308. for (int index = 0; index < AC_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6311. {
  6312. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6313. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6315. {
  6316. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6317. }
  6318. else
  6319. {
  6320. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6321. }
  6322. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6323. goto end;
  6324. }
  6325. }
  6326. }
  6327. //The reservationId does NOT match the reservationId
  6328. sendCancelReservationConfirmation(uuid, comfirmstr);
  6329. end:
  6330. // Fill in ocpp packet uuid
  6331. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6332. return result;
  6333. }
  6334. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6335. {
  6336. mtrace();
  6337. int result = FAIL;
  6338. int gunIndex = 0;
  6339. char typeStr[16]={0};
  6340. char comfirmstr[20];
  6341. int specificId = FALSE;
  6342. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6343. json_object *ChangeAvailability;
  6344. ChangeAvailability = json_tokener_parse(payload);
  6345. if(!is_error(ChangeAvailability))
  6346. {
  6347. // Required data
  6348. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6349. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6350. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6351. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6352. }
  6353. json_object_put(ChangeAvailability);
  6354. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6355. {
  6356. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6357. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6358. }
  6359. else if(gunIndex == 0)
  6360. {
  6361. for(int i=0; i < gunTotalNumber; i++)
  6362. {
  6363. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6364. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6365. }
  6366. }
  6367. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6369. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6370. {
  6371. specificId = TRUE;
  6372. }
  6373. if(specificId == FALSE)
  6374. goto end;
  6375. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6376. {
  6377. //----------------------gunIndex is 0 ------------------------------------------------//
  6378. if(gunIndex == 0)
  6379. {
  6380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6381. {
  6382. for(int i=0; i < gunTotalNumber; i++)
  6383. {
  6384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6385. {
  6386. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6387. {
  6388. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6389. {
  6390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6391. goto end;
  6392. }
  6393. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6394. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6398. {
  6399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6400. goto end;
  6401. }
  6402. }
  6403. }//END FOR CHAdeMO_QUANTITY
  6404. for (int index = 0; index < CCS_QUANTITY; index++)
  6405. {
  6406. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6407. {
  6408. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6409. {
  6410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6411. goto end;
  6412. }
  6413. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6418. {
  6419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6420. goto end;
  6421. }
  6422. }
  6423. }//END FOR CCS_QUANTITY
  6424. for (int index = 0; index < GB_QUANTITY; index++)
  6425. {
  6426. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6427. {
  6428. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6429. {
  6430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6431. goto end;
  6432. }
  6433. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6434. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6438. {
  6439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6440. goto end;
  6441. }
  6442. }
  6443. }// END FOR GB_QUANTITY
  6444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6445. {
  6446. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6447. {
  6448. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6449. {
  6450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6451. goto end;
  6452. }
  6453. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6454. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6458. {
  6459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6460. goto end;
  6461. }
  6462. }
  6463. }// END FOR GENERAL_GUN_QUANTITY
  6464. for (int index = 0; index < AC_QUANTITY; index++)
  6465. {
  6466. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6467. {
  6468. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6469. {
  6470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6471. goto end;
  6472. }
  6473. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6475. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6476. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6478. {
  6479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6480. goto end;
  6481. }
  6482. }
  6483. }//END FOR AC_QUANTITY
  6484. }// END FOR gunTotalNumber
  6485. }
  6486. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6487. {
  6488. for(int i=0; i < gunTotalNumber; i++)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6491. {
  6492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6493. goto end;
  6494. }
  6495. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6496. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6497. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6499. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6500. {
  6501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6502. goto end;
  6503. }
  6504. }
  6505. }
  6506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6507. goto end;
  6508. }
  6509. //----------------------gunIndex is not 0 ------------------------------------------------//
  6510. //check Transaction active
  6511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6512. {
  6513. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6514. {
  6515. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6516. {
  6517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6518. goto end;
  6519. }
  6520. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6523. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6524. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6525. {
  6526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6527. goto end;
  6528. }
  6529. else
  6530. {
  6531. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6533. goto end;
  6534. }
  6535. }
  6536. }//END FOR CHAdeMO_QUANTITY
  6537. for (int index = 0; index < CCS_QUANTITY; index++)
  6538. {
  6539. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6540. {
  6541. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6542. {
  6543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6544. goto end;
  6545. }
  6546. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6547. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6548. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6550. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6551. {
  6552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6553. goto end;
  6554. }
  6555. else
  6556. {
  6557. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6559. goto end;
  6560. }
  6561. }
  6562. }//END FOR CCS_QUANTITY
  6563. for (int index = 0; index < GB_QUANTITY; index++)
  6564. {
  6565. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6566. {
  6567. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6568. {
  6569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6570. goto end;
  6571. }
  6572. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6573. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6574. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6575. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6576. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6577. {
  6578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6579. goto end;
  6580. }
  6581. else
  6582. {
  6583. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6585. goto end;
  6586. }
  6587. }
  6588. }// END FOR GB_QUANTITY
  6589. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6590. {
  6591. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6592. {
  6593. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6594. {
  6595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6596. goto end;
  6597. }
  6598. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6599. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6600. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6603. {
  6604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6605. goto end;
  6606. }
  6607. else
  6608. {
  6609. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6611. goto end;
  6612. }
  6613. }
  6614. }// END FOR GENERAL_GUN_QUANTITY
  6615. for (int index = 0; index < AC_QUANTITY; index++)
  6616. {
  6617. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6618. {
  6619. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6620. {
  6621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6622. goto end;
  6623. }
  6624. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6629. {
  6630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6631. goto end;
  6632. }
  6633. else
  6634. {
  6635. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6637. goto end;
  6638. }
  6639. }
  6640. }//END FOR AC_QUANTITY
  6641. }//END FOR AvailabilityTypeStr[Inoperative]
  6642. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6643. {
  6644. //----------------------gunIndex is 0 ------------------------------------------------//
  6645. if(gunIndex == 0)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6648. {
  6649. for(int i=0; i < gunTotalNumber; i++)
  6650. {
  6651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6652. {
  6653. 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
  6654. {
  6655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6656. goto end;
  6657. }
  6658. }//END FOR CHAdeMO_QUANTITY
  6659. for (int index = 0; index < CCS_QUANTITY; index++)
  6660. {
  6661. 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
  6662. {
  6663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6664. goto end;
  6665. }
  6666. }//END FOR CCS_QUANTITY
  6667. for (int index = 0; index < GB_QUANTITY; index++)
  6668. {
  6669. 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
  6670. {
  6671. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6673. goto end;
  6674. }
  6675. }// END FOR GB_QUANTITY
  6676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6677. {
  6678. 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
  6679. {
  6680. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6682. goto end;
  6683. }
  6684. }// END FOR GENERAL_GUN_QUANTITY
  6685. for (int index = 0; index < AC_QUANTITY; index++)
  6686. {
  6687. 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
  6688. {
  6689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6690. goto end;
  6691. }
  6692. }//END FOR CHAdeMO_QUANTITY
  6693. }// END FOR gunTotalNumber
  6694. }
  6695. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6696. {
  6697. for(int i=0; i < gunTotalNumber; i++)
  6698. {
  6699. for (int index = 0; index < AC_QUANTITY; index++)
  6700. {
  6701. 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
  6702. {
  6703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6704. goto end;
  6705. }
  6706. }//END FOR CHAdeMO_QUANTITY
  6707. } // END FOR gunTotalNumber
  6708. }
  6709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6710. goto end;
  6711. }
  6712. //----------------------gunIndex is not 0 ------------------------------------------------//
  6713. //check Transaction active
  6714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6715. {
  6716. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6717. {
  6718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6719. goto end;
  6720. }
  6721. }//END FOR CHAdeMO_QUANTITY
  6722. for (int index = 0; index < CCS_QUANTITY; index++)
  6723. {
  6724. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6725. {
  6726. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6727. goto end;
  6728. }
  6729. }//END FOR CCS_QUANTITY
  6730. for (int index = 0; index < GB_QUANTITY; index++)
  6731. {
  6732. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6733. {
  6734. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6735. goto end;
  6736. }
  6737. }// END FOR GB_QUANTITY
  6738. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6739. {
  6740. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6741. {
  6742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6743. goto end;
  6744. }
  6745. }// END FOR GENERAL_GUN_QUANTITY
  6746. for (int index = 0; index < AC_QUANTITY; index++)
  6747. {
  6748. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6749. {
  6750. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6751. goto end;
  6752. }
  6753. }//END FOR AC_QUANTITY
  6754. }//END FOR AvailabilityTypeStr[Operative]
  6755. end:
  6756. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6757. {
  6758. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6759. }
  6760. else
  6761. {
  6762. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6763. }
  6764. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6765. {
  6766. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6767. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6768. }
  6769. else if(gunIndex == 0)
  6770. {
  6771. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6772. {
  6773. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6774. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6775. }
  6776. }
  6777. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6778. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6779. return result;
  6780. }
  6781. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6782. {
  6783. mtrace();
  6784. int result = FAIL;
  6785. char keystr[40]={0};
  6786. char valuestr[256]={0};
  6787. char comfirmstr[20]={0};
  6788. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6789. json_object *ChangeConfiguration;
  6790. ChangeConfiguration = json_tokener_parse(payload);
  6791. if(!is_error(ChangeConfiguration))
  6792. {
  6793. // Required data
  6794. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6795. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6796. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6797. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6798. }
  6799. json_object_put(ChangeConfiguration);
  6800. if((uuid==NULL) || (payload ==NULL) )
  6801. {
  6802. DEBUG_ERROR("Payload is null\n");
  6803. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6804. }
  6805. else
  6806. {
  6807. int status = setKeyValue(keystr, valuestr);
  6808. switch(status)
  6809. {
  6810. case ConfigurationStatus_Accepted:
  6811. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6812. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  6813. StoreConfigurationTable();
  6814. break;
  6815. case RebootRequired:
  6816. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6817. StoreConfigurationTable();
  6818. break;
  6819. case NotSupported:
  6820. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6821. break;
  6822. case ConfigurationStatus_Rejected:
  6823. default:
  6824. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6825. break;
  6826. }
  6827. }
  6828. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6829. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  6830. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6831. {
  6832. ChageWebSocketPingInterval(atoi(valuestr));
  6833. }
  6834. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6835. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6836. {
  6837. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6838. SetOcppConnStatus(FALSE);
  6839. }
  6840. return result;
  6841. }
  6842. int handleClearCacheRequest(char *uuid, char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. char comfirmstr[20];
  6847. char rmFileCmd[100]={0};
  6848. struct stat stats;
  6849. DEBUG_INFO("handleClearCacheRequest...\n");
  6850. stat("/Storage/OCPP_PH", &stats);
  6851. // Check for directory existence
  6852. if (S_ISDIR(stats.st_mode) == 1)
  6853. {}
  6854. else
  6855. {
  6856. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6857. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  6858. system(rmFileCmd);
  6859. }
  6860. if(OCPP_cleanLocalCache())
  6861. {
  6862. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6863. }
  6864. else
  6865. {
  6866. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6867. }
  6868. sendClearCacheConfirmation(uuid, comfirmstr);
  6869. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6870. return result;
  6871. }
  6872. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6873. {
  6874. mtrace();
  6875. int result = FAIL;
  6876. int resultRename;
  6877. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6878. char chargingProfilePurposeStr[26]={0};
  6879. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6880. char tempchargingProfilePurposeStr[26]={0};
  6881. char str[100]={0};
  6882. char fname[200]={0};
  6883. char comfirmstr[20]={0};
  6884. char word[1600]={0};
  6885. int clearflag = FALSE;
  6886. int chargingProfileIdIsNULL = FALSE;
  6887. int connectorIsNULL = FALSE;
  6888. int chargingProfilePurposeIsNULL = FALSE;
  6889. int stackLevelIsNULL = FALSE;
  6890. //int GotoEnd = FALSE;
  6891. FILE *fptr1, *fptr2;
  6892. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  6893. int n_chargingProfile=0;
  6894. int isEmptyFile = FALSE;
  6895. char sLineWord[1600]={0};
  6896. char chargingProfiles[10][100]={0};
  6897. int ChargeProfileCount = 0;
  6898. int ch;
  6899. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6900. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6901. json_object *ClearChargingProfile;
  6902. ClearChargingProfile = json_tokener_parse(payload);
  6903. if(!is_error(ClearChargingProfile))
  6904. {
  6905. // Optional data
  6906. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6907. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6908. else
  6909. chargingProfileIdIsNULL = TRUE;
  6910. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6911. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6912. else
  6913. connectorIsNULL = TRUE;
  6914. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6915. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6916. else
  6917. chargingProfilePurposeIsNULL = TRUE;
  6918. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6919. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6920. else
  6921. stackLevelIsNULL = TRUE;
  6922. }
  6923. json_object_put(ClearChargingProfile);
  6924. if(connectorIsNULL == FALSE)
  6925. {
  6926. switch(connectorIdInt)
  6927. {
  6928. case 0:
  6929. if(chargingProfilePurposeIsNULL == TRUE)
  6930. {
  6931. int l = 0;
  6932. strcpy(fname, ChargePointMaxProfile_JSON);
  6933. if((access(fname,F_OK))!=-1)
  6934. {
  6935. strcpy(chargingProfiles[l], fname);
  6936. l = l + 1;
  6937. }
  6938. strcpy(fname, TxDefaultProfile_0_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[l], fname);
  6942. l = l + 1;
  6943. }
  6944. ChargeProfileCount = l;
  6945. }
  6946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6947. {
  6948. strcpy(fname, ChargePointMaxProfile_JSON);
  6949. if((access(fname,F_OK))!=-1)
  6950. {
  6951. strcpy(chargingProfiles[0], fname);
  6952. ChargeProfileCount = 1;
  6953. }
  6954. }
  6955. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6956. {
  6957. strcpy(fname, TxDefaultProfile_0_JSON);
  6958. if((access(fname,F_OK))!=-1)
  6959. {
  6960. strcpy(chargingProfiles[0], fname);
  6961. ChargeProfileCount = 1;
  6962. }
  6963. }
  6964. break;
  6965. default:
  6966. if(chargingProfilePurposeIsNULL == TRUE)
  6967. {
  6968. int m = 0;
  6969. memset(fname, 0, ARRAY_SIZE(fname));
  6970. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6971. if((access(fname,F_OK))!=-1)
  6972. {
  6973. strcpy(chargingProfiles[m], fname);
  6974. m = m + 1;
  6975. }
  6976. memset(fname, 0, ARRAY_SIZE(fname));
  6977. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6978. if((access(fname,F_OK))!=-1)
  6979. {
  6980. strcpy(chargingProfiles[m], fname);
  6981. m = m + 1;
  6982. }
  6983. ChargeProfileCount = m;
  6984. }
  6985. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6986. {
  6987. //strcpy(fname, TxDefaultProfile_1_JSON);
  6988. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6989. if((access(fname,F_OK))!=-1)
  6990. {
  6991. strcpy(chargingProfiles[0], fname);
  6992. ChargeProfileCount = 1;
  6993. }
  6994. }
  6995. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6996. {
  6997. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6998. if((access(fname,F_OK))!=-1)
  6999. {
  7000. strcpy(chargingProfiles[0], fname);
  7001. ChargeProfileCount = 1;
  7002. }
  7003. //strcpy(fname, TxProfile_1_JSON);
  7004. }
  7005. //strcpy(fname, ChargePointMaxProfile_JSON );
  7006. break;
  7007. }
  7008. }
  7009. else // Check all Charging Profiles
  7010. {
  7011. int i = 0;
  7012. char fnametemp[200]={0};
  7013. ChargeProfileCount = 0;
  7014. //Check ChargePointMaxProfile.json exit
  7015. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7016. {
  7017. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7018. i = i + 1;
  7019. }
  7020. //Check TxDefaultProfile_0.json exit
  7021. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7022. {
  7023. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7024. i = i + 1;
  7025. }
  7026. //Check TxDefaultProfile_%d.json
  7027. for(int j=1; j <= gunTotalNumber; j++)
  7028. {
  7029. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7030. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7031. if((access(fnametemp,F_OK))!=-1)
  7032. {
  7033. strcpy(chargingProfiles[i], fnametemp);
  7034. i = i + 1;
  7035. }
  7036. }
  7037. //Check TxProfile_%d.json
  7038. for(int j=1; j <= gunTotalNumber; j++)
  7039. {
  7040. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7041. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7042. if((access(fnametemp,F_OK))!=-1)
  7043. {
  7044. strcpy(chargingProfiles[i], fnametemp);
  7045. i = i + 1;
  7046. }
  7047. }
  7048. ChargeProfileCount = i;
  7049. }// End connectorIsNULL is TRUE
  7050. if(ChargeProfileCount == 0)
  7051. {
  7052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7053. goto end;
  7054. }
  7055. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7056. {
  7057. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7058. goto end;
  7059. }
  7060. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7061. {
  7062. memset(str, 0, ARRAY_SIZE(str));
  7063. // clear temp file
  7064. sprintf(str,"rm -f %s",temp);
  7065. system(str);
  7066. for(int k=0; k < ChargeProfileCount; k++)
  7067. {
  7068. memset(str, 0, ARRAY_SIZE(str));
  7069. //clear file in C
  7070. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7071. system(str);
  7072. }
  7073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7074. goto end;
  7075. }
  7076. else if(connectorIsNULL == TRUE)
  7077. {
  7078. for(int k=0; k < ChargeProfileCount; k++)
  7079. {
  7080. fptr1 = fopen(chargingProfiles[k], "r");
  7081. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7082. //Check Charging Profile Count
  7083. while(fscanf(fptr1, "%s", word) != EOF)
  7084. {
  7085. //DEBUG_INFO("word=%s\n",word);
  7086. if(strstr(word, "chargingProfileId")!= NULL)
  7087. {
  7088. //DEBUG_INFO("test chargingProfileId \n");
  7089. n_chargingProfile = n_chargingProfile + 1;
  7090. //DEBUG_INFO("chargingProfileId Found\n");
  7091. }
  7092. }
  7093. rewind(fptr1);
  7094. //search Charging Profile Element
  7095. //int i= 0;
  7096. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7097. {
  7098. json_object *tmpProfilee;
  7099. tmpProfilee = json_tokener_parse(sLineWord);
  7100. if(!is_error(tmpProfilee))
  7101. {
  7102. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7103. {
  7104. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7105. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7106. }
  7107. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7108. {
  7109. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7110. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7111. }
  7112. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7113. {
  7114. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7115. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7116. }
  7117. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7118. {
  7119. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7120. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7121. }
  7122. }
  7123. json_object_put(tmpProfilee);
  7124. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7125. {
  7126. //------- not write to fptr2-------//
  7127. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7128. //clearflag = TRUE;
  7129. }
  7130. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7131. {
  7132. //------- not write to fptr2-------//
  7133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7134. }
  7135. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7136. {
  7137. //------- not write to fptr2-------//
  7138. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7139. }
  7140. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7141. {
  7142. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7143. }
  7144. else
  7145. {
  7146. fprintf(fptr2, sLineWord);//writing data into file
  7147. }
  7148. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7149. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7150. if(clearflag == TRUE)
  7151. {
  7152. fclose(fptr1);
  7153. fclose(fptr2);
  7154. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7155. system(str);
  7156. // clear temp file
  7157. sprintf(str,"rm -f %s",temp);
  7158. system(str);
  7159. }
  7160. else
  7161. {
  7162. fclose(fptr1);
  7163. fclose(fptr2);
  7164. memset(str, 0, ARRAY_SIZE(str));
  7165. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7166. system(str);
  7167. resultRename = rename(temp, chargingProfiles[k]);
  7168. if(resultRename == 0)
  7169. {
  7170. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7171. }
  7172. else
  7173. {
  7174. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7175. }
  7176. if(comfirmstr[0]== 0)
  7177. {
  7178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7179. }
  7180. //Check chargingProfile is empty file
  7181. /*------ Read the file ----------------*/
  7182. fptr1=fopen(chargingProfiles[k],"r");
  7183. ch=fgetc(fptr1);
  7184. rewind(fptr1);
  7185. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7186. if(ch!=EOF)
  7187. {
  7188. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7189. {
  7190. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7191. if(sLineWord[0]=='\0')
  7192. {
  7193. isEmptyFile = TRUE;
  7194. break;
  7195. }
  7196. else
  7197. {
  7198. isEmptyFile = FALSE;
  7199. break;
  7200. }
  7201. }
  7202. }
  7203. else
  7204. isEmptyFile = TRUE;
  7205. fclose(fptr1);
  7206. if(isEmptyFile == TRUE)
  7207. {
  7208. memset(str, 0, ARRAY_SIZE(str));
  7209. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7210. system(str);
  7211. }
  7212. }
  7213. }// End of while(int k=0; k < ChargePointCount; k++)
  7214. }
  7215. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7216. {
  7217. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7218. for(int k=0; k < ChargeProfileCount; k++)
  7219. {
  7220. fptr1 = fopen(chargingProfiles[k], "r");
  7221. fptr2 = fopen(temp, "w+");
  7222. //Check Charging Profile Count
  7223. while(fscanf(fptr1, "%s", word) != EOF)
  7224. {
  7225. //DEBUG_INFO("word=%s\n",word);
  7226. if(strstr(word, "chargingProfileId")!= NULL)
  7227. {
  7228. n_chargingProfile = n_chargingProfile + 1;
  7229. }
  7230. }
  7231. rewind(fptr1);
  7232. //search Charging Profile Element
  7233. //int i= 0;
  7234. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7235. {
  7236. json_object *tmpProfilee;
  7237. tmpProfilee = json_tokener_parse(sLineWord);
  7238. if(!is_error(tmpProfilee))
  7239. {
  7240. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7241. {
  7242. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7243. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7244. }
  7245. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7246. {
  7247. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7248. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7249. }
  7250. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7251. {
  7252. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7253. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7254. }
  7255. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7256. {
  7257. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7258. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7259. }
  7260. }
  7261. json_object_put(tmpProfilee);
  7262. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7263. {
  7264. //------- not write to fptr2-------//
  7265. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7266. //clearflag = TRUE;
  7267. }
  7268. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7269. {
  7270. //------- not write to fptr2-------//
  7271. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7272. }
  7273. else if(stackLevelIsNULL == TRUE)
  7274. {
  7275. //Clear Whole File
  7276. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7277. clearflag = TRUE;
  7278. break;
  7279. }
  7280. else
  7281. {
  7282. fprintf(fptr2, sLineWord);//writing data into file
  7283. }
  7284. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7285. }
  7286. if(clearflag == TRUE)
  7287. {
  7288. fclose(fptr1);
  7289. fclose(fptr2);
  7290. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7291. system(str);
  7292. // clear temp file
  7293. sprintf(str,"rm -f %s",temp);
  7294. system(str);
  7295. }
  7296. else
  7297. {
  7298. fclose(fptr1);
  7299. fclose(fptr2);
  7300. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7301. system(str);
  7302. resultRename = rename(temp, chargingProfiles[k]);
  7303. if(resultRename == 0)
  7304. {
  7305. DEBUG_INFO("File ChargingProfile renamed successfully");
  7306. }
  7307. else
  7308. {
  7309. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7310. }
  7311. if(comfirmstr[0]== 0)
  7312. {
  7313. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7314. }
  7315. //Check chargingProfile is empty file
  7316. /*------ Read the file ----------------*/
  7317. fptr1=fopen(chargingProfiles[k],"r");
  7318. ch=fgetc(fptr1);
  7319. rewind(fptr1);
  7320. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7321. if(ch!=EOF)
  7322. {
  7323. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7324. {
  7325. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7326. if(sLineWord[0]=='\0')
  7327. {
  7328. isEmptyFile = TRUE;
  7329. break;
  7330. }
  7331. else
  7332. {
  7333. isEmptyFile = FALSE;
  7334. break;
  7335. }
  7336. }
  7337. }
  7338. else
  7339. isEmptyFile = TRUE;
  7340. fclose(fptr1);
  7341. if(isEmptyFile == TRUE)
  7342. {
  7343. memset(str, 0, ARRAY_SIZE(str));
  7344. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7345. system(str);
  7346. }
  7347. /*------- End of reading ---------------*/
  7348. }
  7349. } // while(int k=0; k < ChargeProfileCount; k++)
  7350. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7351. end:
  7352. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7353. {
  7354. if(connectorIdInt == 0)
  7355. {
  7356. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7357. {
  7358. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7359. }
  7360. }
  7361. else
  7362. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7363. }
  7364. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7365. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7366. return result;
  7367. }
  7368. void createFirmwareVersionByDataTransfer(void)
  7369. {
  7370. json_object *FirmwareDataTransfer = json_object_new_object();
  7371. // AC & DC model
  7372. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7373. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7374. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7375. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7376. // DC model
  7377. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7378. {
  7379. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7380. {
  7381. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7387. }
  7388. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7389. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7390. {
  7391. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7392. }
  7393. }
  7394. else
  7395. {
  7396. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7397. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7398. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7400. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7401. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7402. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7409. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7410. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7415. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7416. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7417. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7418. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7419. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7420. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7421. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7422. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7423. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7424. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7425. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7426. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7427. }
  7428. // 4G model
  7429. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7430. {
  7431. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7432. }
  7433. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7434. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7435. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7436. json_object_put(FirmwareDataTransfer);
  7437. }
  7438. int handleDataTransferRequest(char *uuid, char *payload)
  7439. {
  7440. mtrace();
  7441. json_object *response = json_object_new_object();
  7442. int result = FAIL;
  7443. char tempvendorId[255]={0};
  7444. char tempmessageId[50]={0};
  7445. char tempdata[512]={0};
  7446. char message[2048]={0};
  7447. DEBUG_INFO("handleDataTransferRequest...\n");
  7448. if((uuid != NULL) && (payload != NULL))
  7449. {
  7450. json_object *DataTransfer;
  7451. DataTransfer = json_tokener_parse(payload);
  7452. if(!is_error(DataTransfer))
  7453. {
  7454. // Required data
  7455. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7456. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7457. // Optional data
  7458. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7459. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7460. if(json_object_object_get(DataTransfer, "data") != NULL)
  7461. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7462. result = PASS;
  7463. }
  7464. json_object_put(DataTransfer);
  7465. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7466. {
  7467. // Send all moudle firmware version on EVSE
  7468. createFirmwareVersionByDataTransfer();
  7469. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7470. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7471. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7472. json_object_put(response);
  7473. }
  7474. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7475. {
  7476. system("/usr/bin/run_tmate_restart.sh &");
  7477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7478. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7479. json_object_put(response);
  7480. }
  7481. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7482. {
  7483. json_object *data;
  7484. data = json_tokener_parse(tempdata);
  7485. if(!is_error(data))
  7486. {
  7487. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7488. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7489. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7490. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7491. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7492. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7497. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7498. }
  7499. else
  7500. {
  7501. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7502. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7503. }
  7504. json_object_put(data);
  7505. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7506. json_object_put(response);
  7507. }
  7508. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7509. {
  7510. json_object *data;
  7511. data = json_tokener_parse(tempdata);
  7512. if(!is_error(data))
  7513. {
  7514. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7515. if(json_object_object_get(data, "idToken") != NULL)
  7516. {
  7517. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7518. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7519. }
  7520. if(json_object_object_get(data, "price") != NULL)
  7521. {
  7522. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7523. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7524. }
  7525. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7526. }
  7527. else
  7528. {
  7529. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7530. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7531. }
  7532. json_object_put(data);
  7533. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7534. json_object_put(response);
  7535. }
  7536. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7537. {
  7538. json_object *data;
  7539. data = json_tokener_parse(tempdata);
  7540. if(!is_error(data))
  7541. {
  7542. if(json_object_object_get(data, "txId") != NULL)
  7543. {
  7544. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7545. for(int idx = 0;idx<gunTotalNumber;idx++)
  7546. {
  7547. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7548. {
  7549. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7550. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7551. if(json_object_object_get(data, "description") != NULL)
  7552. {
  7553. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7554. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7555. }
  7556. }
  7557. }
  7558. }
  7559. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7560. }
  7561. else
  7562. {
  7563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7564. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7565. }
  7566. json_object_put(data);
  7567. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7568. json_object_put(response);
  7569. }
  7570. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7571. {
  7572. json_object *data;
  7573. data = json_tokener_parse(tempdata);
  7574. if(!is_error(data))
  7575. {
  7576. if(json_object_object_get(data, "txId") != NULL)
  7577. {
  7578. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7579. for(int idx = 0;idx<gunTotalNumber;idx++)
  7580. {
  7581. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7582. {
  7583. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7584. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7585. if(json_object_object_get(data, "description") != NULL)
  7586. {
  7587. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7588. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7589. }
  7590. }
  7591. }
  7592. }
  7593. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7594. }
  7595. else
  7596. {
  7597. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7598. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7599. }
  7600. json_object_put(data);
  7601. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7602. json_object_put(response);
  7603. }
  7604. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7605. {
  7606. json_object *data;
  7607. data = json_tokener_parse(tempdata);
  7608. if(!is_error(data))
  7609. {
  7610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7611. if(json_object_object_get(data, "Content_Type") != NULL)
  7612. {
  7613. 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))
  7614. {
  7615. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7616. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7617. {
  7618. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7619. }
  7620. }
  7621. else
  7622. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7623. }
  7624. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7625. }
  7626. else
  7627. {
  7628. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7629. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7630. }
  7631. json_object_put(data);
  7632. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7633. json_object_put(response);
  7634. }
  7635. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7636. {
  7637. json_object *data;
  7638. data = json_tokener_parse(tempdata);
  7639. if(!is_error(data))
  7640. {
  7641. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7642. if(json_object_object_get(data, "Page_Index") != NULL)
  7643. {
  7644. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7645. }
  7646. if(json_object_object_get(data, "Duration") != NULL)
  7647. {
  7648. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7649. }
  7650. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7651. }
  7652. else
  7653. {
  7654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7655. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7656. }
  7657. json_object_put(data);
  7658. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7659. json_object_put(response);
  7660. }
  7661. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7662. {
  7663. json_object *data;
  7664. data = json_tokener_parse(tempdata);
  7665. if(!is_error(data))
  7666. {
  7667. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7668. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7669. {
  7670. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7671. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7672. else
  7673. {
  7674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7675. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7676. }
  7677. }
  7678. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7679. {
  7680. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7681. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7682. else
  7683. {
  7684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7685. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7686. }
  7687. }
  7688. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7689. {
  7690. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7691. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7692. else
  7693. {
  7694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7696. }
  7697. }
  7698. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7699. {
  7700. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7701. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7702. else
  7703. {
  7704. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7705. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7706. }
  7707. }
  7708. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7709. {
  7710. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7711. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7712. else
  7713. {
  7714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7716. }
  7717. }
  7718. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7719. {
  7720. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7721. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7722. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7723. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7724. else
  7725. {
  7726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7727. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7728. }
  7729. }
  7730. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7731. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7732. }
  7733. else
  7734. {
  7735. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7736. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7737. }
  7738. json_object_put(data);
  7739. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7740. json_object_put(response);
  7741. }
  7742. else
  7743. {
  7744. // Can not find valid message id
  7745. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7746. }
  7747. }
  7748. else
  7749. {
  7750. // Payload is null
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7752. }
  7753. LWS_Send(message);
  7754. return result;
  7755. }
  7756. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7757. {
  7758. mtrace();
  7759. int result = FAIL;
  7760. int connectorIdInt, durationInt;
  7761. char chargingRateUnitStr[4]={0};
  7762. char comfirmstr[20];
  7763. int confirmPeriods = 0;
  7764. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7765. json_object *GetCompositeSchedule;
  7766. GetCompositeSchedule = json_tokener_parse(payload);
  7767. if(!is_error(GetCompositeSchedule))
  7768. {
  7769. // Required data
  7770. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7771. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7772. else
  7773. connectorIdInt = -1;
  7774. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7775. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7776. else
  7777. durationInt = 86400;
  7778. // Optional data
  7779. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7780. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7781. }
  7782. json_object_put(GetCompositeSchedule);
  7783. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7784. if((connectorIdInt == 0) ||
  7785. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7786. {
  7787. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7788. struct StructChargingProfile tmpProfile[1];
  7789. if(strstr(chargingRateUnitStr, "W") != NULL)
  7790. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7791. else
  7792. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7793. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7794. {
  7795. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7796. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7797. }
  7798. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7799. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7800. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7801. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7802. {
  7803. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7804. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7805. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7806. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7807. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7808. {
  7809. confirmPeriods = idx;
  7810. break;
  7811. }
  7812. }
  7813. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7814. {
  7815. confirmPeriods += 1;
  7816. }
  7817. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7818. }
  7819. else
  7820. {
  7821. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7822. }
  7823. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7824. return result;
  7825. }
  7826. int handleGetConfigurationRequest(char *uuid, char *payload)
  7827. {
  7828. mtrace();
  7829. int result = FAIL;
  7830. int MaxKeySupported = 0;
  7831. int n_keys = 0;
  7832. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7833. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7834. json_object *GetConfiguration;
  7835. GetConfiguration = json_tokener_parse(payload);
  7836. if(!is_error(GetConfiguration))
  7837. {
  7838. // Optional data
  7839. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7840. {
  7841. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7842. {
  7843. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7844. n_keys = idx + 1;
  7845. }
  7846. }
  7847. }
  7848. json_object_put(GetConfiguration);
  7849. UnknownKeynum = 0;
  7850. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7851. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7852. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7853. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7854. if(n_keys != 0)
  7855. {
  7856. for(int i=0;i<n_keys;i++)
  7857. {
  7858. getKeyValue(requestKey[i]);
  7859. }
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7864. getKeyValue("");
  7865. }
  7866. processUnkownKey();
  7867. sendGetConfigurationConfirmation(uuid);
  7868. return result;
  7869. }
  7870. static char fnamePlusPath[100]={0};
  7871. static char fnamePWithNoPath[60]={0};
  7872. void checkUploadLog(void)
  7873. {
  7874. FILE *fp;
  7875. /* Open the command for reading. */
  7876. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7877. if (fp == NULL) {
  7878. printf("Failed to run command\n" );
  7879. exit(1);
  7880. }
  7881. int ftppathlen = 0;
  7882. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7883. int i = 0;
  7884. /* Read the output a line at a time - output it. */
  7885. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7886. if(i==0)
  7887. {
  7888. ftppathlen = strlen(fnamePlusPath);
  7889. printf("%s\n", fnamePlusPath);
  7890. fnamePlusPath[ftppathlen]='\0';
  7891. break;
  7892. }
  7893. i= i+1;
  7894. }
  7895. /* close */
  7896. pclose(fp);
  7897. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7898. {
  7899. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7900. {
  7901. fnamePlusPath[k]='\0';
  7902. }
  7903. }
  7904. i=1;
  7905. //char fname[60]={0};
  7906. while(i < ftppathlen)
  7907. {
  7908. int len=ftppathlen-i;
  7909. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7910. {
  7911. printf("compare '/' all right\n");
  7912. break;
  7913. }
  7914. i=i+1;
  7915. }
  7916. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7917. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7918. fnamePWithNoPath[i+1] = '\0';
  7919. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7920. {
  7921. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7922. {
  7923. fnamePWithNoPath[j]='\0';
  7924. }
  7925. }
  7926. FILE* fp1 = fopen(fnamePlusPath, "r");
  7927. if (fp1)
  7928. {
  7929. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7930. // file exists
  7931. fclose(fp1);
  7932. }
  7933. else
  7934. {
  7935. // file doesn't exist
  7936. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7937. }
  7938. }
  7939. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7940. {
  7941. mtrace();
  7942. int result = FAIL;
  7943. time_t CurrentTime;
  7944. struct tm *tm;
  7945. pthread_t th_Status;
  7946. CurrentTime = time(NULL);
  7947. tm = localtime(&CurrentTime);
  7948. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7949. 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);
  7950. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7951. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7952. return result;
  7953. }
  7954. void* GetDiagnosticsProcess(void* data)
  7955. {
  7956. pthread_detach(pthread_self());
  7957. mtrace();
  7958. int retriesInt=0, retryIntervalInt=0;
  7959. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7960. 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};
  7961. int port=0;
  7962. int isSuccess = FALSE;
  7963. char ftpbuf[200]={0};
  7964. char cmdBuf[2048];
  7965. struct tm *tmNow;
  7966. time_t CurrentTime;
  7967. struct tm tmStart;
  7968. struct tm tmStop;
  7969. CurrentTime = time(NULL);
  7970. tmNow=localtime(&CurrentTime);
  7971. uint16_t targetYear, targetMonth;
  7972. json_object *GetDiagnostics;
  7973. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7974. GetDiagnostics = json_tokener_parse(data);
  7975. if(!is_error(GetDiagnostics))
  7976. {
  7977. // Required data
  7978. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7979. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7980. // Optional data
  7981. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7982. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7983. else
  7984. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7985. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7986. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7987. else
  7988. retryIntervalInt = 30;
  7989. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7990. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7991. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7992. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7993. }
  7994. json_object_put(GetDiagnostics);
  7995. // Pack log to compress file
  7996. 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) &&
  7997. (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))
  7998. {
  7999. // Pack system log
  8000. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8001. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8002. targetYear = tmStart.tm_year;
  8003. targetMonth = tmStart.tm_mon;
  8004. do
  8005. {
  8006. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8007. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8008. if(targetMonth+1>=13)
  8009. {
  8010. targetYear += 1;
  8011. targetMonth = 1;
  8012. }
  8013. else
  8014. {
  8015. targetMonth += 1;
  8016. }
  8017. }while((targetYear < (tmNow->tm_year+1900)) ||
  8018. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8019. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8020. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8021. system(cmdBuf);
  8022. // Pack charging & event log
  8023. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8024. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8025. targetYear = tmStart.tm_year;
  8026. targetMonth = tmStart.tm_mon;
  8027. do
  8028. {
  8029. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8030. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8031. if(targetMonth+1>=13)
  8032. {
  8033. targetYear += 1;
  8034. targetMonth = 1;
  8035. }
  8036. else
  8037. {
  8038. targetMonth += 1;
  8039. }
  8040. }while((targetYear < (tmNow->tm_year+1900)) ||
  8041. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8042. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8043. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8044. system(cmdBuf);
  8045. // Combine log file
  8046. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8047. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8048. }
  8049. else
  8050. {
  8051. system("exec /root/logPackTools 'log' 6");
  8052. }
  8053. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8054. system(cmdBuf);
  8055. checkUploadLog();
  8056. //****************location*******************/
  8057. if(strcmp(locationstr,"")==0)
  8058. {
  8059. DEBUG_INFO("location is <Empty>!\n");
  8060. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8061. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8062. goto end;
  8063. }
  8064. memset(protocol, 0, ARRAY_SIZE(protocol));
  8065. memset(user, 0, ARRAY_SIZE(user) );
  8066. memset(password, 0, ARRAY_SIZE(password));
  8067. memset(host, 0, ARRAY_SIZE(host));
  8068. memset(path, 0, ARRAY_SIZE(path));
  8069. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8070. memset(host1, 0, ARRAY_SIZE(host1));
  8071. memset(path1, 0, ARRAY_SIZE(path1));
  8072. /*location: ftp://user:password@host:port/path*/
  8073. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8074. if((access(fnamePlusPath,F_OK))!=-1)
  8075. {
  8076. DEBUG_INFO("fnamePlusPath exist.\n");
  8077. }
  8078. else
  8079. {
  8080. DEBUG_INFO("fnamePlusPath not exist!\n");
  8081. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8082. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8083. goto end;
  8084. }
  8085. if(strchr(locationstr,'@')==NULL)
  8086. {
  8087. sscanf(locationstr,
  8088. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8089. protocol, host, &port, path);
  8090. strcpy(user,"anonymous");
  8091. strcpy(password,"");
  8092. }
  8093. else
  8094. {
  8095. //DEBUG_INFO("pch=%s\n", pch);
  8096. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8097. protocol, user, password, host, &port, path);
  8098. }
  8099. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8100. {
  8101. DEBUG_INFO("protocol is not ftp/http ! \n");
  8102. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8103. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8104. goto end;
  8105. }
  8106. if(strncmp(locationstr,"http", 4) == 0)
  8107. {
  8108. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8109. sprintf(ftppath,"/%s", path);
  8110. do
  8111. {
  8112. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8113. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8114. sleep(3);
  8115. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8116. if(!isSuccess)
  8117. {
  8118. DEBUG_INFO("Diagnostics fail.\n");
  8119. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8120. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8121. sleep(retryIntervalInt);
  8122. }
  8123. else
  8124. {
  8125. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8126. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8127. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8128. }
  8129. retriesInt--;
  8130. }while((isSuccess == 0)&&(retriesInt >= 0));
  8131. }
  8132. else
  8133. {
  8134. sscanf(host,"%[^/]%s",host1, path1);
  8135. if(strlen(path) > 0)
  8136. sprintf(ftppath,"/%s", path);
  8137. else
  8138. sprintf(ftppath,"/%s", path1);
  8139. int ftppathlen=strlen(ftppath);
  8140. int i=1;
  8141. char filenametemp[50];
  8142. while(i < ftppathlen)
  8143. {
  8144. int len=ftppathlen-i;
  8145. if(ftppath[len]== 47) // '/' ascll code: 47
  8146. {
  8147. DEBUG_INFO("find '/' all right\n");
  8148. break;
  8149. }
  8150. i=i+1;
  8151. }
  8152. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8153. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8154. filenametemp[i+1] = 0;
  8155. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8156. if(port == 0)
  8157. port = 21;
  8158. do
  8159. {
  8160. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8161. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8162. sleep(3);
  8163. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8164. if(!isSuccess)
  8165. {
  8166. DEBUG_INFO("Diagnostics fail.\n");
  8167. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8168. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8169. sleep(retryIntervalInt);
  8170. }
  8171. else
  8172. {
  8173. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8174. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8175. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8176. }
  8177. retriesInt--;
  8178. }while((!isSuccess)&&(retriesInt >= 0));
  8179. }
  8180. end:
  8181. system("rm -f /mnt/*");
  8182. sleep(5);
  8183. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8184. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8185. pthread_exit(NULL);
  8186. }
  8187. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8188. {
  8189. mtrace();
  8190. int result = FAIL;
  8191. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8192. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8193. {
  8194. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8195. locallistVersion = -1;
  8196. }
  8197. else
  8198. {
  8199. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8200. OCPP_getListVerion();
  8201. }
  8202. //from db.OCPP_getListVerion
  8203. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8204. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8205. sendGetLocalListVersionConfirmation(uuid,"");
  8206. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8207. return result;
  8208. }
  8209. int handleRemoteStartRequest(char *uuid, char *payload)
  8210. {
  8211. mtrace();
  8212. int result = FAIL;
  8213. int connectorIdInt=0;
  8214. int tempIndex = 0;
  8215. int connectorIdIsNULL, chargingProfileIsNULL;
  8216. char comfirmstr[20]={0};
  8217. char cmdBuf[512];
  8218. json_object *RemoteStartTransaction;
  8219. FILE *fp;
  8220. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8221. if(server_pending == TRUE)
  8222. {
  8223. return 0;
  8224. }
  8225. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8226. RemoteStartTransaction = json_tokener_parse(payload);
  8227. if(!is_error(RemoteStartTransaction))
  8228. {
  8229. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8230. {
  8231. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8232. if(connectorIdInt <= gunTotalNumber)
  8233. {
  8234. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8235. // Required data
  8236. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8237. // Optional data
  8238. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8239. {
  8240. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8241. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8242. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8243. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8244. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8245. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8246. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8247. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8248. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8249. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8250. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8251. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8252. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8253. {
  8254. 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")));
  8255. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8256. 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"));
  8257. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8258. 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"));
  8259. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8260. 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")));
  8261. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8262. {
  8263. 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++)
  8264. {
  8265. 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"));
  8266. 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"));
  8267. 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)
  8268. 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"));
  8269. }
  8270. }
  8271. }
  8272. }
  8273. else
  8274. chargingProfileIsNULL = TRUE;
  8275. }
  8276. }
  8277. else
  8278. connectorIdIsNULL = TRUE;
  8279. }
  8280. else
  8281. connectorIdIsNULL = TRUE;
  8282. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8283. {
  8284. DEBUG_WARN("Connector id is NULL\n.");
  8285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8286. goto end;
  8287. }
  8288. /*
  8289. enum _SYSTEM_STATUS
  8290. {
  8291. S_BOOTING = 0,
  8292. S_IDLE, = 1
  8293. S_AUTHORIZING, = 2
  8294. S_REASSIGN_CHECK, = 3
  8295. S_REASSIGN, = 4
  8296. S_PRECHARGE, = 5
  8297. S_PREPARING_FOR_EV, = 6
  8298. S_PREPARING_FOR_EVSE, = 7
  8299. S_CHARGING, = 8
  8300. S_TERMINATING, = 9
  8301. S_COMPLETE, = 10
  8302. S_ALARM, = 11
  8303. S_FAULT = 12
  8304. }
  8305. */
  8306. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8307. {
  8308. //check Transaction active
  8309. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8310. {
  8311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8312. {
  8313. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8314. }
  8315. else
  8316. {
  8317. tempIndex = connectorIdInt -1;
  8318. }
  8319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8320. {
  8321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8322. {
  8323. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8324. {
  8325. //Reserved
  8326. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8327. }
  8328. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8329. {
  8330. //Reserved
  8331. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8332. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8333. goto end;
  8334. }
  8335. else
  8336. {
  8337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8339. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8340. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8341. {
  8342. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8344. goto end;
  8345. }
  8346. }//END FOR ELSE
  8347. }
  8348. }// END FOR CHAdeMO_QUANTITY
  8349. }
  8350. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8351. {
  8352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8353. {
  8354. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8355. }
  8356. else
  8357. {
  8358. tempIndex = connectorIdInt -1;
  8359. }
  8360. for (int index = 0; index < CCS_QUANTITY; index++)
  8361. {
  8362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8363. {
  8364. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8365. {
  8366. //Reserved
  8367. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8368. }
  8369. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8370. {
  8371. //Reserved
  8372. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8373. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8374. goto end;
  8375. }
  8376. else
  8377. {
  8378. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8379. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8380. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8381. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8382. {
  8383. DEBUG_WARN("CCS connector not allow start\n.");
  8384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8385. goto end;
  8386. }
  8387. }// END FOR ELSE
  8388. }
  8389. }// END FOR CCS_QUANTITY
  8390. }
  8391. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8392. {
  8393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8394. {
  8395. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8396. }
  8397. else
  8398. {
  8399. tempIndex = connectorIdInt -1;
  8400. }
  8401. for (int index = 0; index < GB_QUANTITY; index++)
  8402. {
  8403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8404. {
  8405. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8406. {
  8407. //Reserved
  8408. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8409. }
  8410. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8411. {
  8412. //Reserved
  8413. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8415. goto end;
  8416. }
  8417. else
  8418. {
  8419. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8420. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8421. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8422. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8423. {
  8424. DEBUG_WARN("GB connector not allow start\n.");
  8425. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8426. goto end;
  8427. }
  8428. }// END FOR ELSE
  8429. }
  8430. } // END FOR GB_QUANTITY
  8431. }
  8432. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8433. {
  8434. tempIndex = connectorIdInt -1;
  8435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8436. {
  8437. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8438. {
  8439. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8440. {
  8441. //Reserved
  8442. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8443. }
  8444. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8445. {
  8446. //Reserved
  8447. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8449. goto end;
  8450. }
  8451. else
  8452. {
  8453. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8454. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8455. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8456. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8457. {
  8458. DEBUG_WARN("GB connector not allow start\n.");
  8459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8460. goto end;
  8461. }
  8462. }// END FOR ELSE
  8463. }
  8464. } // END FOR GB_QUANTITY
  8465. }
  8466. else
  8467. {
  8468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8469. {
  8470. tempIndex = 2;
  8471. }
  8472. else
  8473. {
  8474. tempIndex = connectorIdInt -1;
  8475. }
  8476. for (int index = 0; index < AC_QUANTITY; index++)
  8477. {
  8478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8479. {
  8480. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8481. {
  8482. //Reserved
  8483. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8484. }
  8485. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8486. {
  8487. //Reserved
  8488. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8490. goto end;
  8491. }
  8492. else
  8493. {
  8494. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8495. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8496. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8497. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8498. {
  8499. DEBUG_WARN("AC connector not allow start\n.");
  8500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8501. goto end;
  8502. }
  8503. }//END FOR ELSE
  8504. }
  8505. }// END FOR AC_QUANTITY
  8506. }
  8507. if(chargingProfileIsNULL == FALSE)
  8508. {
  8509. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8510. {
  8511. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8513. //memset idTag
  8514. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8515. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8516. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8517. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8518. // Save profile to file
  8519. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8520. system(cmdBuf);
  8521. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8522. fp = fopen(cmdBuf, "w");
  8523. 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));
  8524. fclose(fp);
  8525. }
  8526. else
  8527. {
  8528. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8530. }
  8531. }
  8532. else
  8533. {
  8534. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8536. //memset idTag
  8537. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8538. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8539. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8541. }
  8542. }
  8543. else
  8544. {
  8545. DEBUG_WARN("Connector id over\n.");
  8546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8547. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8548. }
  8549. end:
  8550. json_object_put(RemoteStartTransaction);
  8551. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8552. {
  8553. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8554. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8555. }
  8556. //OCPP send RemoteStartConfirmation by first.
  8557. sendRemoteStartConfirmation(uuid, comfirmstr);
  8558. return result;
  8559. }
  8560. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8561. {
  8562. mtrace();
  8563. int result = FAIL;
  8564. int match = FALSE;
  8565. int GunNO = 0;
  8566. int tempIndex = 0;
  8567. int transactionIdInt=0;
  8568. int transactionIdIsNULL= TRUE;
  8569. char comfirmstr[20];
  8570. json_object *RemoteStopTransaction;
  8571. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8572. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8573. if(server_pending == TRUE)
  8574. {
  8575. return 0;
  8576. }
  8577. RemoteStopTransaction = json_tokener_parse(payload);
  8578. if(!is_error(RemoteStopTransaction))
  8579. {
  8580. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8581. {
  8582. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8583. transactionIdIsNULL = FALSE;
  8584. }
  8585. }
  8586. json_object_put(RemoteStopTransaction);
  8587. if(transactionIdIsNULL == FALSE)
  8588. {
  8589. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8590. {
  8591. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8592. {
  8593. //check Transaction active
  8594. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8595. {
  8596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8597. {
  8598. tempIndex = ((gun_index==2) ? 1: 0);
  8599. }
  8600. else
  8601. {
  8602. tempIndex = gun_index;
  8603. }
  8604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8605. {
  8606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8607. {
  8608. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8609. {
  8610. match = TRUE;
  8611. GunNO = gun_index;
  8612. }
  8613. }
  8614. }// END FOR CHAdeMO_QUANTITY
  8615. }
  8616. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8617. {
  8618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8619. {
  8620. tempIndex = ((gun_index==2) ? 1: 0);
  8621. }
  8622. else
  8623. {
  8624. tempIndex = gun_index;
  8625. }
  8626. for (int index = 0; index < CCS_QUANTITY; index++)
  8627. {
  8628. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8629. {
  8630. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8631. {
  8632. match = TRUE;
  8633. GunNO = gun_index;
  8634. }
  8635. }
  8636. }// END FOR CCS_QUANTITY
  8637. }
  8638. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8639. {
  8640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8641. {
  8642. tempIndex = ((gun_index==2) ? 1: 0);
  8643. }
  8644. else
  8645. {
  8646. tempIndex = gun_index;
  8647. }
  8648. for (int index = 0; index < GB_QUANTITY; index++)
  8649. {
  8650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8651. {
  8652. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8653. {
  8654. match = TRUE;
  8655. GunNO = gun_index;
  8656. }
  8657. }
  8658. }// END FOR GB_QUANTITY
  8659. }
  8660. else if(gunType[gun_index] == GUN_TYPE_DO)
  8661. {
  8662. tempIndex = gun_index;
  8663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8664. {
  8665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8666. {
  8667. 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
  8668. {
  8669. match = TRUE;
  8670. GunNO = gun_index;
  8671. }
  8672. }
  8673. }// END FOR GB_QUANTITY
  8674. }
  8675. else
  8676. {
  8677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8678. {
  8679. tempIndex = 2;
  8680. }
  8681. else
  8682. {
  8683. tempIndex = gun_index;
  8684. }
  8685. for (int index = 0; index < AC_QUANTITY; index++)
  8686. {
  8687. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8688. {
  8689. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8690. {
  8691. match = TRUE;
  8692. GunNO = gun_index;
  8693. }
  8694. }
  8695. }// END FOR CHAdeMO_QUANTITY
  8696. } // END FOR AC ELSE
  8697. }// CHECK IF ResponseTransactionId == transactionIdInt
  8698. }//END FOR
  8699. if( match == TRUE)
  8700. {
  8701. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8702. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8703. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8704. }
  8705. else
  8706. {
  8707. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8708. }
  8709. }
  8710. else
  8711. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8712. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8713. return result;
  8714. }
  8715. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8716. {
  8717. mtrace();
  8718. int result = FAIL;
  8719. int connectorIdInt=0, reservationIdInt=0;
  8720. int tempIndex = 0;
  8721. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8722. char comfirmstr[20]={0};
  8723. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8724. int c = 0;
  8725. char *loc;
  8726. //char *ptr;
  8727. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8728. strcpy(sstrtemp, stringtrimspace(payload));
  8729. //***(1)connectorId ****/
  8730. c=0;
  8731. loc = strstr(sstrtemp, "connectorId");
  8732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8733. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8734. {
  8735. sstr[c] = loc[strlen("connectorId")+2+c];
  8736. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8737. c++;
  8738. }
  8739. sstr[c] = '\0';
  8740. connectorIdInt = atoi(sstr);
  8741. //***(2)expiryDate ****/
  8742. loc = strstr(sstrtemp, "expiryDate");
  8743. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8744. c = 0;
  8745. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8746. {
  8747. sstr[c] = loc[3+strlen("expiryDate")+c];
  8748. c++;
  8749. }
  8750. sstr[c] = '\0';
  8751. strcpy(expiryDatestr, sstr);
  8752. //***(3)idTag ****/
  8753. loc = strstr(sstrtemp, "idTag");
  8754. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8755. c = 0;
  8756. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8757. {
  8758. sstr[c] = loc[3+strlen("idTag")+c];
  8759. c++;
  8760. }
  8761. sstr[c] = '\0';
  8762. strcpy(idTagstr, sstr);
  8763. //***(4)parentIdTag ****/
  8764. loc = strstr(sstrtemp, "parentIdTag");
  8765. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8766. c = 0;
  8767. if(loc == NULL)
  8768. {
  8769. strcpy(parentIdTagstr, "");
  8770. }
  8771. else
  8772. {
  8773. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8774. {
  8775. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8776. c++;
  8777. }
  8778. sstr[c] = '\0';
  8779. strcpy(parentIdTagstr, sstr);
  8780. }
  8781. //***(5)reservationId ****/
  8782. c=0;
  8783. loc = strstr(sstrtemp, "reservationId");
  8784. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8785. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8786. {
  8787. sstr[c] = loc[strlen("reservationId")+2+c];
  8788. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8789. c++;
  8790. }
  8791. sstr[c] = '\0';
  8792. reservationIdInt = atoi(sstr);
  8793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8794. /*
  8795. enum SYSTEM_STATUS
  8796. {
  8797. SYS_MODE_BOOTING = 0,
  8798. SYS_MODE_IDLE = 1,
  8799. SYS_MODE_AUTHORIZING = 2,
  8800. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8801. SYS_MODE_REASSIGN = 4,
  8802. SYS_MODE_PREPARING = 5,
  8803. SYS_MODE_PREPARE_FOR_EV = 6,
  8804. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8805. SYS_MODE_CHARGING = 8,
  8806. SYS_MODE_TERMINATING = 9,
  8807. SYS_MODE_COMPLETE = 10,
  8808. SYS_MODE_ALARM = 11,
  8809. SYS_MODE_FAULT = 12,
  8810. SYS_MODE_RESERVATION = 13,
  8811. SYS_MODE_BOOKING = 14,
  8812. SYS_MODE_MAINTAIN = 15,
  8813. SYS_MODE_DEBUG = 16,
  8814. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8815. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8816. SYS_MODE_UPDATE = 19
  8817. };
  8818. */
  8819. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8820. {
  8821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8822. goto end;
  8823. }
  8824. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8825. {
  8826. //check Transaction active
  8827. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8828. {
  8829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8830. {
  8831. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8832. }
  8833. else
  8834. {
  8835. tempIndex = connectorIdInt -1;
  8836. }
  8837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8838. {
  8839. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8840. {
  8841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8842. {
  8843. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8844. {
  8845. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8846. {
  8847. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8849. }
  8850. 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'))
  8851. {
  8852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8853. }
  8854. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8855. {
  8856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8857. }
  8858. else
  8859. {
  8860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8861. }
  8862. }
  8863. 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
  8864. {
  8865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8866. }
  8867. }
  8868. else
  8869. {
  8870. //replace reservation
  8871. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8873. }
  8874. }
  8875. } // END FOR CHAdeMO_QUANTITY
  8876. }
  8877. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8878. {
  8879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8880. {
  8881. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8882. }
  8883. else
  8884. {
  8885. tempIndex = connectorIdInt -1;
  8886. }
  8887. for (int index = 0; index < CCS_QUANTITY; index++)
  8888. {
  8889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8890. {
  8891. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8892. {
  8893. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8894. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8895. {
  8896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8897. {
  8898. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8900. }
  8901. 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'))
  8902. {
  8903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8904. }
  8905. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8906. {
  8907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8908. }
  8909. else
  8910. {
  8911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8912. }
  8913. }
  8914. 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
  8915. {
  8916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8917. }
  8918. }
  8919. else
  8920. {
  8921. //replace reservation
  8922. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8924. }
  8925. }
  8926. } // END FOR CCS_QUANTITY
  8927. }
  8928. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8929. {
  8930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8931. {
  8932. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8933. }
  8934. else
  8935. {
  8936. tempIndex = connectorIdInt -1;
  8937. }
  8938. for (int index = 0; index < GB_QUANTITY; index++)
  8939. {
  8940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8941. {
  8942. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8943. {
  8944. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8945. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8946. {
  8947. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8948. {
  8949. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8951. }
  8952. 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'))
  8953. {
  8954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8955. }
  8956. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8957. {
  8958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8959. }
  8960. else
  8961. {
  8962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8963. }
  8964. }
  8965. 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
  8966. {
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8968. }
  8969. }
  8970. else
  8971. {
  8972. //replace reservation
  8973. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8975. }
  8976. }
  8977. }// END FOR GB_QUANTITY
  8978. }
  8979. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8980. {
  8981. tempIndex = connectorIdInt -1;
  8982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8983. {
  8984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8985. {
  8986. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8987. {
  8988. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8989. 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
  8990. {
  8991. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8992. {
  8993. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8995. }
  8996. 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'))
  8997. {
  8998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8999. }
  9000. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9001. {
  9002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9003. }
  9004. else
  9005. {
  9006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9007. }
  9008. }
  9009. 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
  9010. {
  9011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9012. }
  9013. }
  9014. else
  9015. {
  9016. //replace reservation
  9017. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9019. }
  9020. }
  9021. }// END FOR GB_QUANTITY
  9022. }
  9023. else
  9024. {
  9025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9026. {
  9027. tempIndex = 2;
  9028. }
  9029. else
  9030. {
  9031. tempIndex = (connectorIdInt -1);
  9032. }
  9033. for (int index = 0; index < AC_QUANTITY; index++)
  9034. {
  9035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9036. {
  9037. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9038. {
  9039. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9040. {
  9041. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9042. {
  9043. 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))
  9044. {
  9045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9046. }
  9047. else
  9048. {
  9049. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9051. }
  9052. }
  9053. 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'))
  9054. {
  9055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9056. }
  9057. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9058. {
  9059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9060. }
  9061. else
  9062. {
  9063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9064. }
  9065. }
  9066. 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
  9067. {
  9068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9069. }
  9070. }
  9071. else
  9072. {
  9073. //replace reservation
  9074. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9076. }
  9077. }
  9078. } // END FOR AC_QUANTITY
  9079. }
  9080. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9081. }
  9082. else if(connectorIdInt == 0)
  9083. {
  9084. //check Transaction active
  9085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9086. {
  9087. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9088. {
  9089. 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'))
  9090. {
  9091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9092. goto end;
  9093. }
  9094. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9095. {
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9097. goto end;
  9098. }
  9099. 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
  9100. {
  9101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9102. goto end;
  9103. }
  9104. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9105. {
  9106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9107. goto end;
  9108. }
  9109. }
  9110. }// END FOR CHAdeMO_QUANTITY
  9111. for (int index = 0; index < CCS_QUANTITY; index++)
  9112. {
  9113. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9114. {
  9115. 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'))
  9116. {
  9117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9118. goto end;
  9119. }
  9120. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9121. {
  9122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9123. goto end;
  9124. }
  9125. 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
  9126. {
  9127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9128. goto end;
  9129. }
  9130. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9131. {
  9132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9133. goto end;
  9134. }
  9135. }
  9136. } // END FOR CCS_QUANTITY
  9137. for (int index = 0; index < GB_QUANTITY; index++)
  9138. {
  9139. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9140. {
  9141. 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'))
  9142. {
  9143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9144. goto end;
  9145. }
  9146. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9147. {
  9148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9149. goto end;
  9150. }
  9151. 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
  9152. {
  9153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9154. goto end;
  9155. }
  9156. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9157. {
  9158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9159. goto end;
  9160. }
  9161. }
  9162. } // END FOR GB_QUANTITY
  9163. for (int index = 0; index < AC_QUANTITY; index++)
  9164. {
  9165. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9166. {
  9167. 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'))
  9168. {
  9169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9170. goto end;
  9171. }
  9172. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9173. {
  9174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9175. goto end;
  9176. }
  9177. 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
  9178. {
  9179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9180. goto end;
  9181. }
  9182. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9183. {
  9184. 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))
  9185. {
  9186. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9187. goto end;
  9188. }
  9189. }
  9190. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9191. {
  9192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9193. goto end;
  9194. }
  9195. }
  9196. }// END FOR AC_QUANTITY
  9197. //The connectorId is 0
  9198. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9200. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9201. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9202. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9203. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9204. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9205. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9206. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9207. result = TRUE;
  9208. return result;
  9209. }
  9210. else
  9211. {
  9212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9213. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9214. }
  9215. if(strcmp(comfirmstr,"Accepted") == 0)
  9216. {
  9217. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9218. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9219. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9220. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9221. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9222. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9223. result = TRUE;
  9224. return result;
  9225. }
  9226. end:
  9227. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9228. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9229. return result;
  9230. }
  9231. int handleResetRequest(char *uuid, char *payload)
  9232. {
  9233. mtrace();
  9234. int result = FAIL;
  9235. char sstr[10]={0},sstrtemp[30]={ 0 };
  9236. char typestr[10]={0};
  9237. char comfirmstr[20]={0};
  9238. int c = 0;
  9239. char *loc;
  9240. DEBUG_INFO("handleResetRequest...\n");
  9241. strcpy(sstrtemp, stringtrimspace(payload));
  9242. loc = strstr(sstrtemp, "type");
  9243. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9244. c = 0;
  9245. while (loc[3+strlen("type")+c] != '\"')
  9246. {
  9247. sstr[c] = loc[3+strlen("type")+c];
  9248. c++;
  9249. }
  9250. sstr[c] = '\0';
  9251. strcpy(typestr,sstr);
  9252. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9253. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9254. {
  9255. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9256. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9257. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9258. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9259. }
  9260. else
  9261. {
  9262. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9263. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9264. result = PASS;
  9265. }
  9266. sendResetConfirmation(uuid, comfirmstr);
  9267. return result;
  9268. }
  9269. int handleSendLocalListRequest(char *uuid, char *payload)
  9270. {
  9271. mtrace();
  9272. int result = FAIL;
  9273. char comfirmstr[20];
  9274. int checkState_Faulted = FALSE;
  9275. json_object *SendLocalList;
  9276. DEBUG_INFO("handleSendLocalListRequest...\n");
  9277. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9278. {
  9279. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9280. goto end;
  9281. }
  9282. //check Charge Point state
  9283. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9284. {
  9285. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9286. {
  9287. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9288. }
  9289. }
  9290. for (int index = 0; index < CCS_QUANTITY; index++)
  9291. {
  9292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9293. {
  9294. checkState_Faulted = TRUE; //OCPP Status
  9295. }
  9296. }
  9297. for (int index = 0; index < GB_QUANTITY; index++)
  9298. {
  9299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9300. {
  9301. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9302. }
  9303. }
  9304. //check Charge Point state
  9305. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9306. {
  9307. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9308. {
  9309. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9310. }
  9311. }
  9312. //check Charge Point state
  9313. for (int index = 0; index < AC_QUANTITY; index++)
  9314. {
  9315. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9316. {
  9317. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9318. }
  9319. }
  9320. if(checkState_Faulted == TRUE)
  9321. {
  9322. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9323. goto end;
  9324. }
  9325. // Parsing payload
  9326. SendLocalList = json_tokener_parse(payload);
  9327. if(!is_error(SendLocalList))
  9328. {
  9329. // Required data
  9330. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9331. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9332. // Optional data
  9333. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9334. {
  9335. //Check UpdateType
  9336. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9337. {
  9338. //Local list full update
  9339. DEBUG_INFO("Local list full update.\n");
  9340. OCPP_getListVerion();
  9341. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9342. {
  9343. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9344. goto end;
  9345. }
  9346. OCPP_cleanLocalList();
  9347. }
  9348. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9349. {
  9350. //Local list different update
  9351. DEBUG_INFO("Local list different update.\n");
  9352. OCPP_getListVerion();
  9353. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9354. {
  9355. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9356. goto end;
  9357. }
  9358. }
  9359. else
  9360. {
  9361. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9362. goto end;
  9363. }
  9364. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9365. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9366. {
  9367. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9368. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9369. {
  9370. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  9371. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9372. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  9373. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9374. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  9375. }
  9376. // Add to db
  9377. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9378. {
  9379. //Local list full update
  9380. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9381. idx,
  9382. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9383. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9384. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9385. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9386. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9387. // update list
  9388. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9389. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9390. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9391. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9392. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9393. }
  9394. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9395. {
  9396. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9397. idx,
  9398. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9399. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9400. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9401. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9402. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9403. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9404. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9405. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9406. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9407. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9408. }
  9409. }
  9410. }
  9411. else
  9412. {
  9413. //Check UpdateType
  9414. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9415. {
  9416. //Local list full update
  9417. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9418. OCPP_cleanLocalList();
  9419. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9420. goto end;
  9421. }
  9422. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9423. {
  9424. //Local list different update
  9425. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9426. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9427. goto end;
  9428. }
  9429. }
  9430. result = PASS;
  9431. }
  9432. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9433. end:
  9434. json_object_put(SendLocalList);
  9435. sendSendLocalListConfirmation(uuid, comfirmstr);
  9436. return result;
  9437. }
  9438. #define MAX 200
  9439. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9440. {
  9441. mtrace();
  9442. int result = FAIL;
  9443. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9444. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9445. char chargingProfilePurposeStr[30]={0};
  9446. char chargingProfileKindStr[16]={0};
  9447. char recurrencyKindStr[10]={0};
  9448. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9449. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9450. int chargingSchedulePeriodCount = 0;
  9451. char comfirmstr[20]={0};
  9452. int meet= FALSE;
  9453. FILE *fptr1;
  9454. char filename[MAX]={0};
  9455. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9456. char rmFileCmd[50]={0};
  9457. char tempchargingProfilePurposeStr[30]={0};
  9458. char word[1600]={0};
  9459. int n_chargingProfile = 0;
  9460. json_object *SetChargingProfile;
  9461. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9462. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9463. SetChargingProfile = json_tokener_parse(payload);
  9464. if(!is_error(SetChargingProfile))
  9465. {
  9466. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9467. {
  9468. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9469. if(connectorIdInt == 0)
  9470. {
  9471. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9472. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9473. }
  9474. else
  9475. {
  9476. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9477. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9478. }
  9479. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9480. }
  9481. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9482. {
  9483. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9484. {
  9485. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9486. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9487. {
  9488. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9489. }
  9490. else
  9491. {
  9492. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9493. }
  9494. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9495. }
  9496. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9497. {
  9498. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9500. {
  9501. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9502. }
  9503. else
  9504. {
  9505. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9506. }
  9507. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9508. }
  9509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9510. {
  9511. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9513. {
  9514. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9515. }
  9516. else
  9517. {
  9518. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9519. }
  9520. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9521. }
  9522. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9523. {
  9524. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9525. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9526. {
  9527. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9528. }
  9529. else
  9530. {
  9531. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9532. }
  9533. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9534. }
  9535. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9536. {
  9537. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9538. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9539. {
  9540. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9541. }
  9542. else
  9543. {
  9544. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9545. }
  9546. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9547. }
  9548. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9549. {
  9550. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9552. {
  9553. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9554. }
  9555. else
  9556. {
  9557. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9558. }
  9559. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9560. }
  9561. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9562. {
  9563. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9564. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9565. {
  9566. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9567. }
  9568. else
  9569. {
  9570. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9571. }
  9572. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9573. }
  9574. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9575. {
  9576. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9577. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9578. {
  9579. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9580. }
  9581. else
  9582. {
  9583. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9584. }
  9585. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9586. }
  9587. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9588. {
  9589. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9590. {
  9591. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9592. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9593. {
  9594. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9595. }
  9596. else
  9597. {
  9598. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9599. }
  9600. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9601. }
  9602. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9603. {
  9604. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9605. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9606. {
  9607. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9608. }
  9609. else
  9610. {
  9611. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9612. }
  9613. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9614. }
  9615. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9616. {
  9617. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9618. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9619. {
  9620. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9621. }
  9622. else
  9623. {
  9624. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9625. }
  9626. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9627. }
  9628. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9629. {
  9630. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9631. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9632. {
  9633. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9634. }
  9635. else
  9636. {
  9637. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9638. }
  9639. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9640. }
  9641. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9642. {
  9643. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9644. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9645. if(chargingSchedulePeriodCount <= 10)
  9646. {
  9647. 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++)
  9648. {
  9649. 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)
  9650. {
  9651. startPeriodInt[idxPeriod] = 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"));
  9652. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9653. {
  9654. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9655. }
  9656. else
  9657. {
  9658. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9659. }
  9660. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9661. }
  9662. 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)
  9663. {
  9664. limitflaot[idxPeriod] = 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"));
  9665. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9666. {
  9667. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9668. }
  9669. else
  9670. {
  9671. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9672. }
  9673. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9674. }
  9675. 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)
  9676. {
  9677. numberPhasesInt[idxPeriod] = 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"));
  9678. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9679. {
  9680. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9681. }
  9682. else
  9683. {
  9684. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9685. }
  9686. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9687. }
  9688. }
  9689. }
  9690. }
  9691. }
  9692. }
  9693. }
  9694. json_object_put(SetChargingProfile);
  9695. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9696. {
  9697. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9698. goto end;
  9699. }
  9700. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9701. {
  9702. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9703. if(connectorIdInt != 0)
  9704. {
  9705. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9706. goto end;
  9707. }
  9708. strcpy(filename, ChargePointMaxProfile_JSON );
  9709. fptr1 = fopen(filename, "r");
  9710. if (!fptr1)
  9711. {
  9712. //file not exist
  9713. DEBUG_INFO("Unable to open the input file!!\n");
  9714. fptr1 = fopen(filename, "w+");
  9715. }
  9716. else
  9717. {
  9718. //Check Charging Profile Count
  9719. while(fscanf(fptr1, "%s", word) != EOF)
  9720. {
  9721. //DEBUG_INFO("word=%s\n",word);
  9722. if(strstr(word, "chargingProfileId")!= NULL)
  9723. {
  9724. //DEBUG_INFO("test chargingProfileId \n");
  9725. n_chargingProfile = n_chargingProfile + 1;
  9726. //DEBUG_INFO("chargingProfileId Found\n");
  9727. }
  9728. }
  9729. }
  9730. fclose(fptr1);
  9731. }
  9732. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9733. {
  9734. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9735. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9736. {
  9737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9738. goto end;
  9739. }
  9740. memset(filename, 0, ARRAY_SIZE(filename));
  9741. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9742. fptr1 = fopen(filename, "r");
  9743. if (!fptr1)
  9744. {
  9745. //file not exist
  9746. //DEBUG_INFO("Unable to open the input file!!\n");
  9747. fptr1 = fopen(filename, "w+");
  9748. }
  9749. else
  9750. {
  9751. //Check Charging Profile Count
  9752. while(fscanf(fptr1, "%s", word) != EOF)
  9753. {
  9754. //DEBUG_INFO("word=%s\n",word);
  9755. if(strstr(word, "chargingProfileId")!= NULL)
  9756. {
  9757. //DEBUG_INFO("test chargingProfileId \n");
  9758. n_chargingProfile = n_chargingProfile + 1;
  9759. //DEBUG_INFO("chargingProfileId Found\n");
  9760. }
  9761. }
  9762. }
  9763. fclose(fptr1);
  9764. }
  9765. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9766. {
  9767. //printf("set chargingProfile 1-4\n");
  9768. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9769. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9770. if(connectorIdInt == 0)
  9771. {
  9772. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9773. goto end;
  9774. }
  9775. int tempIndex = 0;
  9776. //check Transaction active
  9777. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9778. {
  9779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9780. {
  9781. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9782. }
  9783. else
  9784. {
  9785. tempIndex = connectorIdInt -1;
  9786. }
  9787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9788. {
  9789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9790. {
  9791. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9792. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9793. {
  9794. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9795. {
  9796. meet = TRUE;
  9797. break;
  9798. }
  9799. }
  9800. }
  9801. }
  9802. }
  9803. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9804. {
  9805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9806. {
  9807. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9808. }
  9809. else
  9810. {
  9811. tempIndex = connectorIdInt -1;
  9812. }
  9813. for (int index = 0; index < CCS_QUANTITY; index++)
  9814. {
  9815. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9816. {
  9817. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9818. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9819. {
  9820. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9821. {
  9822. meet = TRUE;
  9823. break;
  9824. }
  9825. }
  9826. }
  9827. }
  9828. }
  9829. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9830. {
  9831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9832. {
  9833. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9834. }
  9835. else
  9836. {
  9837. tempIndex = connectorIdInt -1;
  9838. }
  9839. for (int index = 0; index < GB_QUANTITY; index++)
  9840. {
  9841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9842. {
  9843. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9844. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9845. {
  9846. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9847. {
  9848. meet = TRUE;
  9849. break;
  9850. }
  9851. }
  9852. }
  9853. }
  9854. }
  9855. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9856. {
  9857. tempIndex = connectorIdInt -1;
  9858. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9859. {
  9860. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9861. {
  9862. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9863. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9864. {
  9865. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9866. {
  9867. meet = TRUE;
  9868. break;
  9869. }
  9870. }
  9871. }
  9872. }
  9873. }
  9874. else
  9875. {
  9876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9877. {
  9878. tempIndex = 2;
  9879. }
  9880. else
  9881. {
  9882. tempIndex = (connectorIdInt -1);
  9883. }
  9884. for (int index = 0; index < AC_QUANTITY; index++)
  9885. {
  9886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9887. {
  9888. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9889. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9890. {
  9891. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9892. {
  9893. meet = TRUE;
  9894. break;
  9895. }
  9896. }
  9897. }
  9898. }
  9899. }
  9900. //check Transaction active
  9901. if(meet == FALSE)
  9902. {
  9903. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9904. goto end;
  9905. }
  9906. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9907. {
  9908. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9909. goto end;
  9910. }
  9911. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9912. fptr1 = fopen(filename, "r");
  9913. if (!fptr1)
  9914. {
  9915. //file not exist
  9916. DEBUG_INFO("Unable to open the input file!!\n");
  9917. fptr1 = fopen(filename, "w+");
  9918. }
  9919. else
  9920. {
  9921. //Check Charging Profile Count
  9922. while(fscanf(fptr1, "%s", word) != EOF)
  9923. {
  9924. //DEBUG_INFO("word=%s\n",word);
  9925. if(strstr(word, "chargingProfileId")!= NULL)
  9926. {
  9927. //DEBUG_INFO("test chargingProfileId \n");
  9928. n_chargingProfile = n_chargingProfile + 1;
  9929. //DEBUG_INFO("chargingProfileId Found\n");
  9930. }
  9931. }
  9932. }
  9933. fclose(fptr1);
  9934. }
  9935. // Check ChargeProfileMaxStackLevel
  9936. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9937. {
  9938. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9939. goto end;
  9940. }
  9941. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9942. {
  9943. int i = 0;
  9944. char fnametemp[200]={0};
  9945. n_chargingProfile = 0;
  9946. //Check ChargePointMaxProfile.json exit
  9947. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  9948. {
  9949. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  9950. //Check Charging Profile Count
  9951. while(fscanf(fptr1, "%s", word) != EOF)
  9952. {
  9953. //DEBUG_INFO("word=%s\n",word);
  9954. if(strstr(word, "chargingProfileId")!= NULL)
  9955. {
  9956. //DEBUG_INFO("test chargingProfileId \n");
  9957. n_chargingProfile = n_chargingProfile + 1;
  9958. i = i + 1;
  9959. //DEBUG_INFO("chargingProfileId Found\n");
  9960. }
  9961. memset(word, 0, ARRAY_SIZE(word));
  9962. }
  9963. fclose(fptr1);
  9964. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9965. }
  9966. //Check TxDefaultProfile_0.json exit
  9967. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  9968. {
  9969. i = 0;
  9970. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  9971. //Check Charging Profile Count
  9972. while(fscanf(fptr1, "%s", word) != EOF)
  9973. {
  9974. //DEBUG_INFO("word=%s\n",word);
  9975. if(strstr(word, "chargingProfileId")!= NULL)
  9976. {
  9977. //DEBUG_INFO("test chargingProfileId \n");
  9978. n_chargingProfile = n_chargingProfile + 1;
  9979. i = i + 1;
  9980. //DEBUG_INFO("chargingProfileId Found\n");
  9981. }
  9982. memset(word, 0, ARRAY_SIZE(word));
  9983. }
  9984. fclose(fptr1);
  9985. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9986. }
  9987. //Check TxDefaultProfile_%d.json
  9988. for(int j=1; j <= gunTotalNumber; j++)
  9989. {
  9990. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9991. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  9992. if((access(fnametemp,F_OK))!=-1)
  9993. {
  9994. i = 0;
  9995. fptr1 = fopen(fnametemp, "r");
  9996. //Check Charging Profile Count
  9997. while(fscanf(fptr1, "%s", word) != EOF)
  9998. {
  9999. //DEBUG_INFO("word=%s\n",word);
  10000. if(strstr(word, "chargingProfileId")!= NULL)
  10001. {
  10002. //DEBUG_INFO("test chargingProfileId \n");
  10003. n_chargingProfile = n_chargingProfile + 1;
  10004. i = i + 1;
  10005. //DEBUG_INFO("chargingProfileId Found\n");
  10006. }
  10007. memset(word, 0, ARRAY_SIZE(word));
  10008. }
  10009. fclose(fptr1);
  10010. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10011. }
  10012. }
  10013. //Check TxProfile_%d.json
  10014. for(int j=1; j <= gunTotalNumber; j++)
  10015. {
  10016. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10017. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10018. if((access(fnametemp,F_OK))!=-1)
  10019. {
  10020. i = 0;
  10021. fptr1 = fopen(fnametemp, "r");
  10022. //Check Charging Profile Count
  10023. while(fscanf(fptr1, "%s", word) != EOF)
  10024. {
  10025. //DEBUG_INFO("word=%s\n",word);
  10026. if(strstr(word, "chargingProfileId")!= NULL)
  10027. {
  10028. //DEBUG_INFO("test chargingProfileId \n");
  10029. n_chargingProfile = n_chargingProfile + 1;
  10030. i = i + 1;
  10031. //DEBUG_INFO("chargingProfileId Found\n");
  10032. }
  10033. memset(word, 0, ARRAY_SIZE(word));
  10034. }
  10035. fclose(fptr1);
  10036. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10037. }
  10038. }
  10039. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10040. {
  10041. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10042. goto end;
  10043. }
  10044. }
  10045. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10046. //**********************************Write to File********************************************************/
  10047. FILE *infile;
  10048. FILE *outfile;
  10049. infile = fopen (filename, "r");
  10050. outfile = fopen (tempfile, "w");
  10051. int d =0;
  10052. d = fgetc(infile);
  10053. rewind(infile);
  10054. if(d == EOF)
  10055. {
  10056. // Profile is empty
  10057. fprintf(outfile,"%s\n",payload);
  10058. fclose(infile);
  10059. fclose(outfile);
  10060. sprintf(rmFileCmd,"rm -f %s",filename);
  10061. system(rmFileCmd);
  10062. rename(tempfile, filename);
  10063. }
  10064. else
  10065. {
  10066. // Profile is not empty
  10067. char buf[2048]={0};
  10068. int ChargingProfileAdded = FALSE;
  10069. while (fgets(buf, sizeof(buf), infile) != NULL)
  10070. {
  10071. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10072. json_object *tmpChargingProfile;
  10073. tmpChargingProfile = json_tokener_parse(buf);
  10074. if(!is_error(SetChargingProfile))
  10075. {
  10076. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10077. {
  10078. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10079. }
  10080. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10081. {
  10082. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10083. {
  10084. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10085. }
  10086. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10087. {
  10088. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10089. }
  10090. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10091. {
  10092. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10093. }
  10094. }
  10095. }
  10096. json_object_put(tmpChargingProfile);
  10097. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10098. {
  10099. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10100. {
  10101. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10102. if(ChargingProfileAdded == FALSE)
  10103. {
  10104. fprintf(outfile,"%s\n",payload);
  10105. ChargingProfileAdded = TRUE;
  10106. }
  10107. }
  10108. else
  10109. {
  10110. if(tempstackLevelInt < stackLevelInt)
  10111. {
  10112. if(ChargingProfileAdded == FALSE)
  10113. {
  10114. fprintf(outfile,"%s\n",buf);
  10115. fprintf(outfile,"%s\n",payload);
  10116. ChargingProfileAdded = TRUE;
  10117. }
  10118. else
  10119. {
  10120. fprintf(outfile,"%s\n",buf);
  10121. }
  10122. }
  10123. else
  10124. {
  10125. if(ChargingProfileAdded == FALSE)
  10126. {
  10127. fprintf(outfile,"%s\n",buf);
  10128. fprintf(outfile,"%s\n",payload);
  10129. ChargingProfileAdded = TRUE;
  10130. }
  10131. else
  10132. {
  10133. fprintf(outfile,"%s\n",buf);
  10134. }
  10135. }
  10136. }
  10137. }
  10138. else
  10139. {
  10140. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10141. {
  10142. if(ChargingProfileAdded == FALSE)
  10143. {
  10144. fprintf(outfile,"%s\n",buf);
  10145. fprintf(outfile,"%s\n",payload);
  10146. ChargingProfileAdded = TRUE;
  10147. }
  10148. else
  10149. {
  10150. fprintf(outfile,"%s\n",buf);
  10151. }
  10152. }
  10153. else if(tempstackLevelInt < stackLevelInt)
  10154. {
  10155. if(ChargingProfileAdded == FALSE)
  10156. {
  10157. fprintf(outfile,"%s\n",buf);
  10158. fprintf(outfile,"%s\n",payload);
  10159. ChargingProfileAdded = TRUE;
  10160. }
  10161. else
  10162. {
  10163. fprintf(outfile,"%s\n",buf);
  10164. }
  10165. }
  10166. else
  10167. {
  10168. if(ChargingProfileAdded == FALSE)
  10169. {
  10170. fprintf(outfile,"%s\n",buf);
  10171. fprintf(outfile,"%s\n",payload);
  10172. ChargingProfileAdded = TRUE;
  10173. }
  10174. else
  10175. {
  10176. fprintf(outfile,"%s\n",buf);
  10177. }
  10178. }
  10179. }
  10180. } // end of while loop
  10181. fclose(infile);
  10182. fclose(outfile);
  10183. sprintf(rmFileCmd,"rm -f %s",filename);
  10184. system(rmFileCmd);
  10185. rename(tempfile, filename);
  10186. }
  10187. sleep(1);
  10188. result = TRUE;
  10189. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10190. end:
  10191. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10192. {
  10193. if(connectorIdInt == 0)
  10194. {
  10195. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10196. {
  10197. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10198. }
  10199. }
  10200. else
  10201. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10202. }
  10203. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10204. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10205. return result;
  10206. }
  10207. int handleTriggerMessageRequest(char *uuid, char *payload)
  10208. {
  10209. mtrace();
  10210. int result = FAIL;
  10211. int connectorIdIsNULL = FALSE;
  10212. int connectorIdInt =0;
  10213. char sstr[40]={0},sstrtemp[100]={ 0 };
  10214. char requestedMessagestr[40]={0};
  10215. char comfirmstr[20]={0};
  10216. int c = 0;
  10217. char *loc;
  10218. DEBUG_INFO("handleTriggerMessageRequest\n");
  10219. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10220. strcpy(sstrtemp, stringtrimspace(payload));
  10221. c = 0;
  10222. loc = strstr(sstrtemp, "requestedMessage");
  10223. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10224. {
  10225. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10226. c++;
  10227. }
  10228. sstr[c] = '\0';
  10229. strcpy(requestedMessagestr, sstr);
  10230. c = 0;
  10231. loc = strstr(sstrtemp, "connectorId");
  10232. if(loc == NULL)
  10233. {
  10234. connectorIdIsNULL = TRUE;
  10235. }
  10236. else
  10237. {
  10238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10239. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10240. {
  10241. sstr[c] = loc[strlen("connectorId")+2+c];
  10242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10243. c++;
  10244. }
  10245. sstr[c] = '\0';
  10246. connectorIdInt = atoi(sstr);
  10247. }
  10248. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10249. {
  10250. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10251. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10252. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10253. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10254. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10255. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10256. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10257. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10258. {
  10259. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10260. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10261. return TRUE;
  10262. }
  10263. else
  10264. {
  10265. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10266. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10267. }
  10268. }
  10269. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10270. {
  10271. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10272. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10273. return TRUE;
  10274. }
  10275. //==========================
  10276. // Trigger message
  10277. //==========================
  10278. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10279. {
  10280. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10281. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10282. {
  10283. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10284. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10285. }
  10286. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10287. }
  10288. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10289. {
  10290. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10291. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10292. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10293. }
  10294. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10295. {
  10296. //sendBootNotificationRequest();
  10297. server_sign = FALSE;
  10298. }
  10299. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10300. {
  10301. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10302. }
  10303. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10304. {
  10305. if(connectorIdIsNULL == FALSE)
  10306. {
  10307. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10308. {
  10309. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10310. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10311. }
  10312. }
  10313. else
  10314. {
  10315. for(int idx=0;idx< gunTotalNumber;idx++)
  10316. {
  10317. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10318. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10319. }
  10320. }
  10321. }
  10322. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10323. {
  10324. if(connectorIdIsNULL == FALSE)
  10325. {
  10326. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10327. {
  10328. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10329. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10330. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10331. }
  10332. }
  10333. else
  10334. {
  10335. for(int idx=0;idx< gunTotalNumber;idx++)
  10336. {
  10337. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10338. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10339. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10340. }
  10341. }
  10342. }
  10343. return result;
  10344. }
  10345. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10346. {
  10347. mtrace();
  10348. int result = FAIL;
  10349. int connectorIdInt =0;
  10350. char comfirmstr[20]={0};
  10351. int tempIndex = 0;
  10352. json_object *UnlockConnector;
  10353. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10354. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10355. UnlockConnector = json_tokener_parse(payload);
  10356. if(!is_error(UnlockConnector))
  10357. {
  10358. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10359. {
  10360. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10361. }
  10362. }
  10363. json_object_put(UnlockConnector);
  10364. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10365. if(gunTotalNumber == 0)
  10366. {
  10367. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10368. goto end;
  10369. }
  10370. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10371. {
  10372. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10373. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10374. goto end;
  10375. }
  10376. else
  10377. {
  10378. //check Transaction active
  10379. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10380. {
  10381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10382. {
  10383. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10384. }
  10385. else
  10386. {
  10387. tempIndex = connectorIdInt -1;
  10388. }
  10389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10390. {
  10391. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10392. {
  10393. //stop Transaction
  10394. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10395. }
  10396. }
  10397. }
  10398. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10399. {
  10400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10401. {
  10402. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10403. }
  10404. else
  10405. {
  10406. tempIndex = connectorIdInt -1;
  10407. }
  10408. for (int index = 0; index < CCS_QUANTITY; index++)
  10409. {
  10410. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10411. {
  10412. //stop Transaction
  10413. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10414. }
  10415. }
  10416. }
  10417. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10418. {
  10419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10420. {
  10421. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10422. }
  10423. else
  10424. {
  10425. tempIndex = connectorIdInt -1;
  10426. }
  10427. for (int index = 0; index < GB_QUANTITY; index++)
  10428. {
  10429. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10430. {
  10431. //stop Transaction
  10432. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10433. }
  10434. }
  10435. }
  10436. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10437. {
  10438. tempIndex = connectorIdInt -1;
  10439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10440. {
  10441. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  10442. {
  10443. //stop Transaction
  10444. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10445. }
  10446. }
  10447. }
  10448. else
  10449. {
  10450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10451. {
  10452. tempIndex = 2;
  10453. }
  10454. else
  10455. {
  10456. tempIndex = connectorIdInt-1;
  10457. }
  10458. for (int index = 0; index < AC_QUANTITY; index++)
  10459. {
  10460. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10461. {
  10462. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10463. }
  10464. }
  10465. }
  10466. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10467. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10468. result = TRUE;
  10469. return result;
  10470. }
  10471. end:
  10472. //json_object_put(obj); --- remove temporally
  10473. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10474. return result;
  10475. }
  10476. static char UpdateFirmwarepayloadData[300]={0};
  10477. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10478. {
  10479. mtrace();
  10480. int result = FAIL;
  10481. pthread_t t;
  10482. sendUpdateFirmwareConfirmation(uuid);
  10483. memset(UpdateFirmwarepayloadData, 0, 300);
  10484. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10485. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10486. ////pthread_join(t, NULL); //
  10487. //pthread_detach(t);
  10488. //sendUpdateFirmwareConfirmation(uuid);
  10489. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10490. return result;
  10491. }
  10492. void *UpdateFirmwareProcess(void *data)
  10493. {
  10494. pthread_detach(pthread_self());
  10495. mtrace();
  10496. int retriesInt =0, retryIntervalInt=0;
  10497. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10498. int port=0;
  10499. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10500. int isSuccess = 0;
  10501. char ftpbuf[512];
  10502. char temp[100];
  10503. char * pch;
  10504. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10505. json_object *UpdateFirmware;
  10506. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10507. if(!is_error(UpdateFirmware))
  10508. {
  10509. // Required data
  10510. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10511. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10512. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10513. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10514. // Optional data
  10515. if(json_object_object_get(UpdateFirmware, "retries"))
  10516. {
  10517. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10518. }
  10519. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10520. {
  10521. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10522. }
  10523. }
  10524. json_object_put(UpdateFirmware);
  10525. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10526. memset(path, 0, ARRAY_SIZE(path));
  10527. // Wait retrieveData
  10528. if(strlen(retrieveDatestr) > 10)
  10529. {
  10530. do
  10531. {
  10532. sleep(1);
  10533. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10534. }
  10535. // Ready to download
  10536. system("rm -f /mnt/*");
  10537. if(strncmp(locationstr,"http", 4) == 0)
  10538. {
  10539. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10540. sprintf(ftppath,"/%s", path);
  10541. DEBUG_INFO("locationstr: %s\n", locationstr);
  10542. DEBUG_INFO("protocol: %s\n",protocol);
  10543. DEBUG_INFO("host: %s\n",host);
  10544. DEBUG_INFO("path: %s\n",path);
  10545. DEBUG_INFO("ftppath: %s\n",ftppath);
  10546. int ftppathlen=strlen(ftppath);
  10547. int i=1;
  10548. char filenametemp[50];
  10549. while(i < ftppathlen)
  10550. {
  10551. int len=ftppathlen-i;
  10552. if(ftppath[len]== 47) // '/' ascll code: 47
  10553. {
  10554. DEBUG_INFO("compare '/' all right\n");
  10555. break;
  10556. }
  10557. i=i+1;
  10558. }
  10559. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10560. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10561. filenametemp[i+1] = 0;
  10562. do
  10563. {
  10564. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10565. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10566. sleep(1);
  10567. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10568. if(!isSuccess)
  10569. {
  10570. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10571. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10572. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10573. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10574. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10575. }
  10576. else
  10577. {
  10578. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10579. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10580. }
  10581. retriesInt--;
  10582. }while((isSuccess == 0)&&(retriesInt >= 0));
  10583. }
  10584. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10585. {
  10586. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10587. memset(temp, 0, ARRAY_SIZE(temp));
  10588. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10589. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10590. int ftppathlen=strlen(ftpbuf);
  10591. int i=1;
  10592. char filenametemp[50];
  10593. while(i < ftppathlen)
  10594. {
  10595. int len=ftppathlen-i;
  10596. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10597. {
  10598. DEBUG_INFO(" compare '/' all right\n");
  10599. break;
  10600. }
  10601. i=i+1;
  10602. }
  10603. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10604. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10605. filenametemp[i+1] = 0;
  10606. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10607. pch=strchr(temp,'@');
  10608. if(pch==NULL)
  10609. {
  10610. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10611. protocol, host, &port, path);
  10612. strcpy(user,"anonymous");
  10613. strcpy(password,"");
  10614. }
  10615. else
  10616. {
  10617. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10618. protocol, user, password, host, &port, path);
  10619. }
  10620. sscanf(host,"%[^/]%s",host1, path1);
  10621. sprintf(ftppath,"%s", path1);
  10622. //DEBUG_INFO("protocol =%s\n",protocol);
  10623. //DEBUG_INFO("user =%s\n",user);
  10624. //DEBUG_INFO("password =%s\n",password);
  10625. //DEBUG_INFO("host1 =%s\n",host1);
  10626. //DEBUG_INFO("port =%d\n",port);
  10627. //DEBUG_INFO("path1 =%s\n",path1);
  10628. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10629. //ftpFile(host, user, password, port, ftppath, fname);
  10630. //download firmware pthred
  10631. if(port == 0)
  10632. {
  10633. port = 21;
  10634. }
  10635. do
  10636. {
  10637. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10638. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10639. sleep(1);
  10640. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10641. if(!isSuccess)
  10642. {
  10643. //BulldogUtil.sleepMs(interval*1000);
  10644. DEBUG_INFO("Update firmware request and download file fail.\n");
  10645. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10646. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10647. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10648. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10649. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10650. }
  10651. else
  10652. {
  10653. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10654. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10655. }
  10656. retriesInt--;
  10657. }while((!isSuccess)&&(retriesInt >= 0));
  10658. }
  10659. else
  10660. {
  10661. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10662. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10663. sleep(1);
  10664. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10665. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10666. }
  10667. // OCPPPH only, must announce CSU upgrade firmware
  10668. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  10669. pthread_exit(NULL);
  10670. }
  10671. int handleCertificateSignedRequest(char *uuid, char *payload)
  10672. {
  10673. mtrace();
  10674. int result = PASS;
  10675. json_object *CertificateSigned;
  10676. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10677. CertificateSigned = json_tokener_parse(payload);
  10678. if(!is_error(CertificateSigned))
  10679. {
  10680. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10681. }
  10682. json_object_put(CertificateSigned);
  10683. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10684. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10685. fclose(fp);
  10686. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10687. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10688. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10689. sendCertificateSignedConfirmation(uuid);
  10690. return result;
  10691. }
  10692. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10693. {
  10694. mtrace();
  10695. int result = PASS;
  10696. json_object *DeleteCertificate;
  10697. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10698. DeleteCertificate = json_tokener_parse(payload);
  10699. if(!is_error(DeleteCertificate))
  10700. {
  10701. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10702. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10703. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10704. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10705. }
  10706. json_object_put(DeleteCertificate);
  10707. /*
  10708. * TODO: Delete certificateSigned process
  10709. */
  10710. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10711. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10712. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10713. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10714. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10715. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10716. sendDeleteCertificateConfirmation(uuid);
  10717. return result;
  10718. }
  10719. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10720. {
  10721. mtrace();
  10722. int result = PASS;
  10723. json_object *ExtendedTriggerMessage;
  10724. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10725. ExtendedTriggerMessage = json_tokener_parse(payload);
  10726. if(!is_error(ExtendedTriggerMessage))
  10727. {
  10728. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10729. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10730. {
  10731. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10732. }
  10733. else
  10734. {
  10735. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10736. }
  10737. }
  10738. json_object_put(ExtendedTriggerMessage);
  10739. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10740. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10741. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10742. {
  10743. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10744. }
  10745. else
  10746. {
  10747. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10748. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10749. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10750. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10751. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10752. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10753. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10754. {
  10755. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10756. }
  10757. else
  10758. {
  10759. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10760. }
  10761. }
  10762. sendExtendedTriggerMessageConfirmation(uuid);
  10763. //==========================
  10764. // Trigger message
  10765. //==========================
  10766. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10767. {
  10768. //sendBootNotificationRequest();
  10769. server_sign = FALSE;
  10770. }
  10771. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10772. {
  10773. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10774. }
  10775. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10776. {
  10777. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10778. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10779. {
  10780. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10781. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10782. }
  10783. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10784. }
  10785. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10786. {
  10787. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10788. }
  10789. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10790. {
  10791. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10792. {
  10793. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10794. }
  10795. else
  10796. {
  10797. for(int idx=0;idx< gunTotalNumber;idx++)
  10798. {
  10799. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10800. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10801. }
  10802. }
  10803. }
  10804. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10805. {
  10806. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10807. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10808. {
  10809. 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\" &");
  10810. }
  10811. }
  10812. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10813. {
  10814. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10815. {
  10816. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10817. }
  10818. else
  10819. {
  10820. for(int idx=0;idx< gunTotalNumber;idx++)
  10821. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10822. }
  10823. }
  10824. return result;
  10825. }
  10826. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10827. {
  10828. mtrace();
  10829. int result = PASS;
  10830. json_object *GetInstalledCertificateIds;
  10831. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10832. GetInstalledCertificateIds = json_tokener_parse(payload);
  10833. if(!is_error(GetInstalledCertificateIds))
  10834. {
  10835. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10836. }
  10837. json_object_put(GetInstalledCertificateIds);
  10838. /*
  10839. * TODO: Return installed certificate process
  10840. */
  10841. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10842. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10843. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10844. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10845. sendGetInstalledCertificateIdsConfirmation(uuid);
  10846. return result;
  10847. }
  10848. int handleGetLogRequest(char *uuid, char *payload)
  10849. {
  10850. mtrace();
  10851. int result = PASS;
  10852. json_object *GetLog;
  10853. DEBUG_INFO("handleGetLogRequest...\n");
  10854. GetLog = json_tokener_parse(payload);
  10855. if(!is_error(GetLog))
  10856. {
  10857. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10858. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10859. if(json_object_object_get(GetLog, "retries") != NULL)
  10860. {
  10861. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10862. }
  10863. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10864. {
  10865. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10866. }
  10867. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10868. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10869. {
  10870. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10871. }
  10872. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10873. {
  10874. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10875. }
  10876. }
  10877. json_object_put(GetLog);
  10878. /*
  10879. * TODO: Upload log process
  10880. */
  10881. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10882. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10883. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10884. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10885. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10886. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10887. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10888. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10889. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10890. sendGetLogConfirmation(uuid);
  10891. return result;
  10892. }
  10893. int handleInstallCertificateRequest(char *uuid, char *payload)
  10894. {
  10895. mtrace();
  10896. int result = PASS;
  10897. json_object *InstallCertificate;
  10898. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10899. InstallCertificate = json_tokener_parse(payload);
  10900. if(!is_error(InstallCertificate))
  10901. {
  10902. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10903. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10904. /*
  10905. * TODO: Install certificate process
  10906. */
  10907. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  10908. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  10909. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  10910. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  10911. sendInstallCertificateConfirmation(uuid);
  10912. }
  10913. json_object_put(InstallCertificate);
  10914. return result;
  10915. }
  10916. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10917. {
  10918. mtrace();
  10919. int result = PASS;
  10920. json_object *SignedUpdateFirmware;
  10921. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10922. SignedUpdateFirmware = json_tokener_parse(payload);
  10923. if(!is_error(SignedUpdateFirmware))
  10924. {
  10925. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10926. {
  10927. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10928. }
  10929. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10930. {
  10931. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10932. }
  10933. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10934. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10935. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10936. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10937. {
  10938. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10939. }
  10940. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10941. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10942. }
  10943. json_object_put(SignedUpdateFirmware);
  10944. /*
  10945. * TODO: Upgrade firmware process
  10946. */
  10947. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10948. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  10949. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  10950. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  10951. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  10952. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  10953. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  10954. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  10955. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  10956. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  10957. sendInstallCertificateConfirmation(uuid);
  10958. return result;
  10959. }
  10960. int handleUnknownRequest(char *uuid, char *payload)
  10961. {
  10962. mtrace();
  10963. int result = PASS;
  10964. DEBUG_INFO("handleUnknownRequest...\n");
  10965. sendUnknownConfirmation(uuid);
  10966. result = PASS;
  10967. return result;
  10968. }
  10969. //==========================================
  10970. // Handle server response routine
  10971. //==========================================
  10972. void handleAuthorizeResponse(char *payload, int gun_index)
  10973. {
  10974. mtrace();
  10975. char expiryDatestr[30]={0};
  10976. char parentIdTagstr[20]={0};
  10977. char statusstr[20]={0};
  10978. int expiryDateISNULL=FALSE;
  10979. int parentIdTagISNULL=FALSE;
  10980. DEBUG_INFO("handleAuthorizeResponse...\n");
  10981. json_object *Authorize;
  10982. Authorize = json_tokener_parse(payload);
  10983. if(!is_error(Authorize))
  10984. {
  10985. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10986. {
  10987. // Required data
  10988. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10989. // Optional data
  10990. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10991. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10992. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10993. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10994. }
  10995. }
  10996. json_object_put(Authorize);
  10997. if(expiryDateISNULL == FALSE)
  10998. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10999. if(parentIdTagISNULL == FALSE)
  11000. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11001. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11002. //Update idTag information to authorization cache if supproted
  11003. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11004. {
  11005. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11006. }
  11007. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11008. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11009. authorizeRetryTimes = 0;
  11010. }
  11011. void handleBootNotificationResponse(char *payload, int gun_index)
  11012. {
  11013. mtrace();
  11014. char statusStr[12]={0};
  11015. char currentTimeStr[30]={0};
  11016. int intervalInt = 0;
  11017. DEBUG_INFO("handleBootNotificationResponse...\n");
  11018. json_object *BootNotification;
  11019. BootNotification = json_tokener_parse(payload);
  11020. if(!is_error(BootNotification))
  11021. {
  11022. // Required data
  11023. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11024. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11025. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11026. }
  11027. json_object_put(BootNotification);
  11028. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11029. BootNotificationInterval = intervalInt;
  11030. HeartBeatWaitTime = intervalInt;
  11031. //write back to ShmOCPP16DataPH->BootNotification
  11032. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11033. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11034. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11035. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11036. {
  11037. server_sign = TRUE;
  11038. server_pending =FALSE;
  11039. }
  11040. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11041. {
  11042. server_pending = TRUE;
  11043. }
  11044. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11045. srand(time(NULL));
  11046. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11047. SetOcppConnStatus(TRUE);
  11048. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11049. }
  11050. void handleDataTransferResponse(char *payload, int gun_index)
  11051. {
  11052. char sstr[160]={0};//sstr[200]={ 0 };
  11053. int c = 0;
  11054. char *loc;
  11055. DEBUG_INFO("handleDataTransferResponse ...\n");
  11056. loc = strstr(payload, "status");
  11057. printf("loc=%s\n",loc);
  11058. c = 0;
  11059. while (loc[3+strlen("status")+c] != '\"')
  11060. {
  11061. sstr[c] = loc[3+strlen("status")+c];
  11062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11063. c++;
  11064. }
  11065. sstr[c] = '\0';
  11066. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11067. }
  11068. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11069. {
  11070. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11071. //struct json_object *obj;
  11072. // obj = json_tokener_parse(payload);
  11073. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11074. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11075. //No fields are defined.
  11076. }
  11077. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11078. {
  11079. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11080. //struct json_object *obj;
  11081. // obj = json_tokener_parse(payload);
  11082. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11083. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11084. //No fields are defined.
  11085. }
  11086. void handleHeartbeatResponse(char *payload, int gun_index)
  11087. {
  11088. mtrace();
  11089. DEBUG_INFO("handleHeartbeatResponse...\n");
  11090. json_object *Heartbeat;
  11091. Heartbeat = json_tokener_parse(payload);
  11092. if(!is_error(Heartbeat))
  11093. {
  11094. // Required data
  11095. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11096. }
  11097. json_object_put(Heartbeat);
  11098. if(FirstHeartBeat == 0)
  11099. {
  11100. FirstHeartBeat = 1;
  11101. DEBUG_INFO("FirstHeartBeat \n");
  11102. }
  11103. HeartBeatWithNOResponse = 0;
  11104. clientTime.Heartbeat=time((time_t*)NULL);
  11105. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11106. }
  11107. void handleMeterValuesResponse(char *payload, int gun_index)
  11108. {
  11109. mtrace();
  11110. DEBUG_INFO("handleMeterValuesResponse...\n");
  11111. }
  11112. void handleStartTransactionResponse(char *payload, int gun_index)
  11113. {
  11114. mtrace();
  11115. //int transactionIdInt = 0;
  11116. FILE *outfile;
  11117. char data[100]={0};
  11118. DEBUG_INFO("handleStartTransactionResponse...\n");
  11119. json_object *StartTransaction;
  11120. StartTransaction = json_tokener_parse(payload);
  11121. if(!is_error(StartTransaction))
  11122. {
  11123. // Required data
  11124. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11125. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11126. // Optional data
  11127. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11128. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11129. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11130. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11131. }
  11132. json_object_put(StartTransaction);
  11133. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11134. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11135. //-----------Start : write to the Queue TransactionId file -----------------//
  11136. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11137. {}
  11138. else
  11139. {
  11140. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11141. if(log == NULL)
  11142. {
  11143. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11144. return ;
  11145. }
  11146. else
  11147. {
  11148. fclose(log);
  11149. }
  11150. }
  11151. // open file for writing
  11152. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11153. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11154. {
  11155. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11156. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11157. fputs(data, outfile);
  11158. fclose (outfile);
  11159. }
  11160. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11161. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11162. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11163. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11164. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11165. }
  11166. void handleStatusNotificationResponse(char *payload, int gun_index)
  11167. {
  11168. mtrace();
  11169. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11170. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11172. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11173. }
  11174. void handleStopTransactionnResponse(char *payload, int gun_index)
  11175. {
  11176. mtrace();
  11177. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11178. json_object *StopTransaction;
  11179. StopTransaction = json_tokener_parse(payload);
  11180. if(!is_error(StopTransaction))
  11181. {
  11182. // Optional data
  11183. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11184. {
  11185. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11186. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11188. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11189. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11190. }
  11191. }
  11192. json_object_put(StopTransaction);
  11193. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11194. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11195. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11196. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11197. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11198. }
  11199. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11200. {
  11201. mtrace();
  11202. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11203. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11204. }
  11205. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11206. {
  11207. mtrace();
  11208. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11209. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11210. }
  11211. void handleSignCertificateResponse(char *payload, int gun_index)
  11212. {
  11213. mtrace();
  11214. DEBUG_INFO("handleSignCertificateResponse...\n");
  11215. json_object *SignCertificate;
  11216. SignCertificate = json_tokener_parse(payload);
  11217. if(!is_error(SignCertificate))
  11218. {
  11219. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11220. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11221. }
  11222. json_object_put(SignCertificate);
  11223. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11224. }
  11225. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11226. {
  11227. mtrace();
  11228. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11229. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11230. }
  11231. //==========================================
  11232. // Handle Error routine
  11233. //==========================================
  11234. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11235. {
  11236. mtrace();
  11237. #ifdef SystemLogMessage
  11238. DEBUG_INFO("errorCode: %s\n", errorCode);
  11239. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11240. DEBUG_INFO("errorDetails: %s\n", payload);
  11241. #endif
  11242. }
  11243. //===============================================
  11244. // Common routine
  11245. //===============================================
  11246. int initialConfigurationTable(void)
  11247. {
  11248. //clock_t start_t, end_t, total_t;
  11249. FILE *fp;
  11250. FILE *outfile;
  11251. char str[512]={0};
  11252. char sstr[256]={0};
  11253. int c = 0;
  11254. char *loc;
  11255. int confVersion = 3;
  11256. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11257. //start_t = clock();
  11258. //printf("Starting of the program, start_t = %ld\n", start_t);
  11259. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11260. // Check configuration file size is correct
  11261. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11262. {
  11263. struct stat st;
  11264. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11265. if(st.st_size < 3100)
  11266. {
  11267. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11268. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11269. }
  11270. }
  11271. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11272. {
  11273. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11274. if(outfile == NULL)
  11275. {
  11276. DEBUG_INFO("Error opening file\n");
  11277. return FALSE;
  11278. }
  11279. /*Core Profile*/
  11280. //AllowOfflineTxForUnknownId
  11281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11285. //AuthorizationCacheEnabled
  11286. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11290. //AuthorizeRemoteTxRequests
  11291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11295. //BlinkRepeat
  11296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11300. //ClockAlignedDataInterval
  11301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11305. //ConnectionTimeOut
  11306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11310. //GetConfigurationMaxKeys
  11311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11315. // HeartbeatInterval
  11316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11320. // LightIntensity
  11321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11325. // LocalAuthorizeOffline
  11326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11330. // LocalPreAuthorize
  11331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11335. // MaxEnergyOnInvalidId
  11336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11340. // MeterValuesAlignedData
  11341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11345. else
  11346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11348. // MeterValuesAlignedDataMaxLength
  11349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11353. else
  11354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11356. // MeterValuesSampledData
  11357. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11359. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11361. else
  11362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11364. // MeterValuesSampledDataMaxLength
  11365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11369. else
  11370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11372. // MeterValueSampleInterval
  11373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11377. // MinimumStatusDuration
  11378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11381. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11383. // NumberOfConnectors
  11384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11387. {
  11388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11389. }
  11390. else
  11391. {
  11392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11393. }
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11395. // ResetRetries
  11396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11400. // ConnectorPhaseRotation
  11401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11405. // ConnectorPhaseRotationMaxLength
  11406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11410. // StopTransactionOnEVSideDisconnect
  11411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11415. // StopTransactionOnInvalidId
  11416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11420. // StopTxnAlignedData
  11421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11425. // StopTxnAlignedDataMaxLength
  11426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11430. // StopTxnSampledData
  11431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11435. else
  11436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11438. // StopTxnSampledDataMaxLength
  11439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11442. {
  11443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11444. }
  11445. else
  11446. {
  11447. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11448. }
  11449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11450. // SupportedFeatureProfiles
  11451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11455. // SupportedFeatureProfilesMaxLength
  11456. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11460. // TransactionMessageAttempts
  11461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11464. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11466. // TransactionMessageRetryInterval
  11467. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11469. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11470. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11472. // UnlockConnectorOnEVSideDisconnect
  11473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11474. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11477. // WebSocketPingInterval
  11478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11482. // QueueOffLineStartTransactionMessage
  11483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11485. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11487. // AuthorizationKey
  11488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11492. // SecurityProfile
  11493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11497. // DefaultPrice
  11498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11502. // CustomDisplayCostAndPrice
  11503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11507. // CustomIdleFeeAfterStop
  11508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11512. // Configuration Version
  11513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11517. //* Local Auth List Management Profile*/
  11518. #if 0
  11519. //For OCTT Test Case
  11520. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11521. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11523. #endif
  11524. #if 1
  11525. //LocalAuthListEnabled
  11526. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11530. #endif
  11531. //LocalAuthListMaxLength
  11532. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11536. //SendLocalListMaxLength
  11537. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11541. //ReserveConnectorZeroSupported
  11542. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11546. //* Smart Charging Profile */
  11547. //ChargeProfileMaxStackLevel
  11548. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11552. // ChargingScheduleAllowedChargingRateUnit
  11553. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11557. // ChargingScheduleMaxPeriods
  11558. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11562. // ConnectorSwitch3to1PhaseSupported
  11563. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11567. // MaxChargingProfilesInstalled
  11568. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11572. fclose(outfile);
  11573. }
  11574. else
  11575. {
  11576. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11577. char keystr[60]={0};
  11578. char readonlystr[10]={0};
  11579. char valuestr[256]={0};
  11580. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11581. if(fp == NULL) {
  11582. DEBUG_INFO("Error opening file");
  11583. return FALSE;
  11584. }
  11585. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11586. {
  11587. //DEBUG_INFO("Get Configuration \n");
  11588. if(strlen(str) > 0)
  11589. {
  11590. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11591. //*************************key*********************************/
  11592. if(strstr(str, "key") != NULL)
  11593. {
  11594. loc = strstr(str, "key");
  11595. c = 0;
  11596. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11597. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11598. {
  11599. sstr[c] = loc[strlen("key")+3+c];
  11600. c++;
  11601. }
  11602. sstr[c] = '\0';
  11603. strcpy(keystr,sstr);
  11604. }
  11605. //*************************readonly*********************************/
  11606. if(strstr(str, "readonly") != NULL)
  11607. {
  11608. loc = strstr(str, "readonly");
  11609. c = 0;
  11610. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11611. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11612. {
  11613. sstr[c] = loc[strlen("readonly")+2+c];
  11614. c++;
  11615. }
  11616. sstr[c] = '\0';
  11617. strcpy(readonlystr,sstr);
  11618. }
  11619. //*************************value*********************************/
  11620. if(strstr(str, "value") != NULL)
  11621. {
  11622. loc = strstr(str, "value");
  11623. c = 0;
  11624. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11625. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11626. {
  11627. sstr[c] = loc[strlen("value")+3+c];
  11628. c++;
  11629. }
  11630. sstr[c] = '\0';
  11631. strcpy(valuestr,sstr);
  11632. }
  11633. // DEBUG_INFO("keystr=%s\n",keystr);
  11634. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11635. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11636. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11637. {
  11638. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11639. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11641. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11642. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11643. }
  11644. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11645. {
  11646. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11649. }
  11650. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11651. {
  11652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11654. }
  11655. if(strcmp(keystr, "BlinkRepeat") == 0)
  11656. {
  11657. //Charger.BlinkRepeat = Integer.parseInt(value);
  11658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11660. }
  11661. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11662. {
  11663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11665. }
  11666. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11667. {
  11668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11670. }
  11671. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11672. {
  11673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11675. }
  11676. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11677. {
  11678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11680. HeartBeatWaitTime = atoi(valuestr);
  11681. }
  11682. if(strcmp(keystr, "LightIntensity") == 0)
  11683. {
  11684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11686. }
  11687. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11688. {
  11689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11691. }
  11692. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11693. {
  11694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11696. }
  11697. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11698. {
  11699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11701. }
  11702. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11703. {
  11704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11706. }
  11707. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11708. {
  11709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11711. }
  11712. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11713. {
  11714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11716. }
  11717. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11718. {
  11719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11721. }
  11722. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11723. {
  11724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11726. }
  11727. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11728. {
  11729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11731. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11732. }
  11733. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11734. {
  11735. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11736. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11737. }
  11738. if(strcmp(keystr, "ResetRetries") == 0)
  11739. {
  11740. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11742. }
  11743. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11744. {
  11745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11747. }
  11748. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11749. {
  11750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11752. }
  11753. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11754. {
  11755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11757. }
  11758. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11759. {
  11760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11762. }
  11763. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11764. {
  11765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11767. }
  11768. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11769. {
  11770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11772. }
  11773. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11774. {
  11775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11777. }
  11778. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11779. {
  11780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11782. }
  11783. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11784. {
  11785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11787. }
  11788. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11789. {
  11790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11791. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11792. }
  11793. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11794. {
  11795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11796. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11797. TransactionMessageAttemptsValue = atoi(valuestr);
  11798. }
  11799. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11800. {
  11801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11803. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11804. }
  11805. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11806. {
  11807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11809. }
  11810. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11811. {
  11812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11814. }
  11815. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11816. {
  11817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11818. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11819. }
  11820. if(strcmp(keystr, "AuthorizationKey") == 0)
  11821. {
  11822. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11823. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11825. }
  11826. if(strcmp(keystr, "SecurityProfile") == 0)
  11827. {
  11828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11829. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11831. }
  11832. if(strcmp(keystr, "DefaultPrice") == 0)
  11833. {
  11834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11835. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11836. }
  11837. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11838. {
  11839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11840. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11841. }
  11842. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11843. {
  11844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11846. }
  11847. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11848. {
  11849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11851. }
  11852. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11853. {
  11854. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11856. }
  11857. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11858. {
  11859. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11861. }
  11862. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11863. {
  11864. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11866. }
  11867. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11868. {
  11869. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11871. }
  11872. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11873. {
  11874. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11875. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11876. }
  11877. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11878. {
  11879. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11880. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11881. }
  11882. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11883. {
  11884. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11885. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11886. }
  11887. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11888. {
  11889. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11890. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11891. }
  11892. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11893. {
  11894. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11896. }
  11897. }
  11898. }
  11899. fclose(fp);
  11900. }
  11901. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11902. {
  11903. return PASS;
  11904. }
  11905. else
  11906. {
  11907. return FAIL;
  11908. }
  11909. }
  11910. void StoreConfigurationTable(void)
  11911. {
  11912. FILE *outfile;
  11913. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11914. if(outfile == NULL)
  11915. {
  11916. DEBUG_INFO("Error opening file");
  11917. return ;
  11918. }
  11919. /*Core Profile*/
  11920. //AllowOfflineTxForUnknownId
  11921. /*
  11922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11923. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11926. */
  11927. //DEBUG_INFO("data=%s\n",data);
  11928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11929. //AuthorizationCacheEnabled
  11930. /*
  11931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11934. */
  11935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11936. //AuthorizeRemoteTxRequests
  11937. /*
  11938. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11941. */
  11942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11943. //BlinkRepeat
  11944. /*
  11945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11948. */
  11949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11950. //ClockAlignedDataInterval
  11951. /*
  11952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11955. */
  11956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11957. //ConnectionTimeOut
  11958. /*
  11959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11962. */
  11963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11964. //GetConfigurationMaxKeys
  11965. /*
  11966. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11969. */
  11970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11971. // HeartbeatInterval
  11972. /*
  11973. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11976. */
  11977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11978. // LightIntensity
  11979. /*
  11980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11983. */
  11984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11985. // LocalAuthorizeOffline
  11986. /*
  11987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11990. */
  11991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11992. // LocalPreAuthorize
  11993. /*
  11994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11997. */
  11998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11999. // MaxEnergyOnInvalidId
  12000. /*
  12001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12004. */
  12005. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12007. // MeterValuesAlignedData
  12008. /*
  12009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12012. */
  12013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12014. // MeterValuesAlignedDataMaxLength
  12015. /*
  12016. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12019. */
  12020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12021. // MeterValuesSampledData
  12022. /*
  12023. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12026. */
  12027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12028. // MeterValuesSampledDataMaxLength
  12029. /*
  12030. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12033. */
  12034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12035. // MeterValueSampleInterval
  12036. /*
  12037. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12040. */
  12041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12042. // MinimumStatusDuration
  12043. /*
  12044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12047. */
  12048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12049. // NumberOfConnectors
  12050. /*
  12051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12054. {
  12055. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12056. }
  12057. else
  12058. {
  12059. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12060. }
  12061. */
  12062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12063. // ResetRetries
  12064. /*
  12065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12068. */
  12069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12070. // ConnectorPhaseRotation
  12071. /*
  12072. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12075. */
  12076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12077. // ConnectorPhaseRotationMaxLength
  12078. /*
  12079. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12082. */
  12083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12084. // StopTransactionOnEVSideDisconnect
  12085. /*
  12086. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12089. */
  12090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12091. // StopTransactionOnInvalidId
  12092. /*
  12093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12096. */
  12097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12098. // StopTxnAlignedData
  12099. /*
  12100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12103. */
  12104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12105. // StopTxnAlignedDataMaxLength
  12106. /*
  12107. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12110. */
  12111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12112. // StopTxnSampledData
  12113. /*
  12114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12117. */
  12118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12119. // StopTxnSampledDataMaxLength
  12120. /*
  12121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12124. */
  12125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12126. // SupportedFeatureProfiles
  12127. /*
  12128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12131. */
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12133. // SupportedFeatureProfilesMaxLength
  12134. /*
  12135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12138. */
  12139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12140. // TransactionMessageAttempts
  12141. /*
  12142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12145. */
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12147. // TransactionMessageRetryInterval
  12148. /*
  12149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12152. */
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12154. // UnlockConnectorOnEVSideDisconnect
  12155. /*
  12156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12159. */
  12160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12161. // WebSocketPingInterval
  12162. /*
  12163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12166. */
  12167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12168. // QueueOffLineStartTransactionMessage
  12169. /*
  12170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12173. */
  12174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12175. // AuthorizationKey
  12176. /*
  12177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12180. */
  12181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12182. // SecurityProfile
  12183. /*
  12184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12187. */
  12188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12189. // DefaultPrice
  12190. /*
  12191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12194. */
  12195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12196. // CustomDisplayCostAndPrice
  12197. /*
  12198. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12201. */
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12203. // CustomIdleFeeAfterStop
  12204. /*
  12205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12208. */
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12210. // ConfigurationVersion
  12211. /*
  12212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12215. */
  12216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12217. //* Local Auth List Management Profile*/
  12218. //LocalAuthListEnabled
  12219. /*
  12220. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12223. */
  12224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12225. //LocalAuthListMaxLength
  12226. /*
  12227. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12230. */
  12231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12232. //SendLocalListMaxLength
  12233. /*
  12234. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12237. */
  12238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12239. //ReserveConnectorZeroSupported
  12240. /*
  12241. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12244. */
  12245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12246. //* Smart Charging Profile */
  12247. //ChargeProfileMaxStackLevel
  12248. /*
  12249. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12252. */
  12253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12254. // ChargingScheduleAllowedChargingRateUnit
  12255. /*
  12256. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12259. */
  12260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12261. // ChargingScheduleMaxPeriods
  12262. /*
  12263. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12266. */
  12267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12268. // ConnectorSwitch3to1PhaseSupported
  12269. /*
  12270. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12273. */
  12274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12275. // MaxChargingProfilesInstalled
  12276. /*
  12277. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12280. */
  12281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12282. fclose(outfile);
  12283. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12284. }
  12285. void getKeyValue(char *keyReq)
  12286. {
  12287. int isEmpty = FALSE;
  12288. int isKnowKey = FALSE;
  12289. DEBUG_INFO("keyReq = %s\n", keyReq);
  12290. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12291. isEmpty = TRUE;
  12292. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12293. {
  12294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12296. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12297. {
  12298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12299. }
  12300. else
  12301. {
  12302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12303. }
  12304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12305. isKnowKey = TRUE;
  12306. }
  12307. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12308. {
  12309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12311. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12312. {
  12313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12314. }
  12315. else
  12316. {
  12317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12318. }
  12319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12320. isKnowKey = TRUE;
  12321. }
  12322. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12323. {
  12324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12327. {
  12328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12329. }
  12330. else
  12331. {
  12332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12333. }
  12334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12335. isKnowKey = TRUE;
  12336. }
  12337. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12338. {
  12339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12341. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12342. {
  12343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12344. }
  12345. else
  12346. {
  12347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12348. }
  12349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12350. isKnowKey = TRUE;
  12351. }
  12352. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12353. {
  12354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12357. {
  12358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12359. }
  12360. else
  12361. {
  12362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12363. }
  12364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12365. isKnowKey = TRUE;
  12366. }
  12367. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12368. {
  12369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12372. {
  12373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12374. }
  12375. else
  12376. {
  12377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12378. }
  12379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12380. isKnowKey = TRUE;
  12381. }
  12382. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12383. {
  12384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12386. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12387. {
  12388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12389. }
  12390. else
  12391. {
  12392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12393. }
  12394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12395. isKnowKey = TRUE;
  12396. }
  12397. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12398. {
  12399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12401. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12402. {
  12403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12404. }
  12405. else
  12406. {
  12407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12408. }
  12409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12410. isKnowKey = TRUE;
  12411. }
  12412. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12413. {
  12414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12416. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12417. {
  12418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12419. }
  12420. else
  12421. {
  12422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12423. }
  12424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12425. isKnowKey = TRUE;
  12426. }
  12427. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12428. {
  12429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12431. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12432. {
  12433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12434. }
  12435. else
  12436. {
  12437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12438. }
  12439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12440. isKnowKey = TRUE;
  12441. }
  12442. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12443. {
  12444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12447. {
  12448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12449. }
  12450. else
  12451. {
  12452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12453. }
  12454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12455. isKnowKey = TRUE;
  12456. }
  12457. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12458. {
  12459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12461. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12462. {
  12463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12464. }
  12465. else
  12466. {
  12467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12468. }
  12469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12470. isKnowKey = TRUE;
  12471. }
  12472. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12473. {
  12474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12477. {
  12478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12479. }
  12480. else
  12481. {
  12482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12483. }
  12484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12485. isKnowKey = TRUE;
  12486. }
  12487. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12488. {
  12489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12492. {
  12493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12494. }
  12495. else
  12496. {
  12497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12498. }
  12499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12500. isKnowKey = TRUE;
  12501. }
  12502. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12503. {
  12504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12506. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12507. {
  12508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12509. }
  12510. else
  12511. {
  12512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12513. }
  12514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12515. isKnowKey = TRUE;
  12516. }
  12517. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12518. {
  12519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12521. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12522. {
  12523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12524. }
  12525. else
  12526. {
  12527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12528. }
  12529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12530. isKnowKey = TRUE;
  12531. }
  12532. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12533. {
  12534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12536. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12537. {
  12538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12539. }
  12540. else
  12541. {
  12542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12543. }
  12544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12545. isKnowKey = TRUE;
  12546. }
  12547. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12548. {
  12549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12551. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12552. {
  12553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12554. }
  12555. else
  12556. {
  12557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12558. }
  12559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12560. isKnowKey = TRUE;
  12561. }
  12562. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12563. {
  12564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12566. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12567. {
  12568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12569. }
  12570. else
  12571. {
  12572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12573. }
  12574. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12576. isKnowKey = TRUE;
  12577. }
  12578. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12579. {
  12580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12583. {
  12584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12585. }
  12586. else
  12587. {
  12588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12589. }
  12590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12591. isKnowKey = TRUE;
  12592. }
  12593. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12594. {
  12595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12597. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12598. {
  12599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12600. }
  12601. else
  12602. {
  12603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12604. }
  12605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12606. isKnowKey = TRUE;
  12607. }
  12608. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12609. {
  12610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12612. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12613. {
  12614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12615. }
  12616. else
  12617. {
  12618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12619. }
  12620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12621. isKnowKey = TRUE;
  12622. }
  12623. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12624. {
  12625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12627. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12628. {
  12629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12630. }
  12631. else
  12632. {
  12633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12634. }
  12635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12636. isKnowKey = TRUE;
  12637. }
  12638. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12639. {
  12640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12642. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12643. {
  12644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12645. }
  12646. else
  12647. {
  12648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12649. }
  12650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12651. isKnowKey = TRUE;
  12652. }
  12653. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12654. {
  12655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12657. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12658. {
  12659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12660. }
  12661. else
  12662. {
  12663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12664. }
  12665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12666. isKnowKey = TRUE;
  12667. }
  12668. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12669. {
  12670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12673. {
  12674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12675. }
  12676. else
  12677. {
  12678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12679. }
  12680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12681. isKnowKey = TRUE;
  12682. }
  12683. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12684. {
  12685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12687. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12688. {
  12689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12690. }
  12691. else
  12692. {
  12693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12694. }
  12695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12696. isKnowKey = TRUE;
  12697. }
  12698. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12699. {
  12700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12702. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12703. {
  12704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12705. }
  12706. else
  12707. {
  12708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12709. }
  12710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12711. isKnowKey = TRUE;
  12712. }
  12713. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12714. {
  12715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12717. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12718. {
  12719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12720. }
  12721. else
  12722. {
  12723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12724. }
  12725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12726. isKnowKey = TRUE;
  12727. }
  12728. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12729. {
  12730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12733. {
  12734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12735. }
  12736. else
  12737. {
  12738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12739. }
  12740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12741. isKnowKey = TRUE;
  12742. }
  12743. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12744. {
  12745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12747. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12748. {
  12749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12750. }
  12751. else
  12752. {
  12753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12754. }
  12755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12756. isKnowKey = TRUE;
  12757. }
  12758. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12759. {
  12760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12762. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12763. {
  12764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12765. }
  12766. else
  12767. {
  12768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12769. }
  12770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12771. isKnowKey = TRUE;
  12772. }
  12773. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12774. {
  12775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12778. {
  12779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12780. }
  12781. else
  12782. {
  12783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12784. }
  12785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12786. isKnowKey = TRUE;
  12787. }
  12788. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12789. {
  12790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12793. {
  12794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12795. }
  12796. else
  12797. {
  12798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12799. }
  12800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12801. isKnowKey = TRUE;
  12802. }
  12803. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12804. {
  12805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12807. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12808. {
  12809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12810. }
  12811. else
  12812. {
  12813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12814. }
  12815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12816. isKnowKey = TRUE;
  12817. }
  12818. /*
  12819. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12820. {
  12821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12824. {
  12825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12826. }
  12827. else
  12828. {
  12829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12830. }
  12831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12832. isKnowKey = TRUE;
  12833. }*/
  12834. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12835. {
  12836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12838. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12839. {
  12840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12841. }
  12842. else
  12843. {
  12844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12845. }
  12846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12847. isKnowKey = TRUE;
  12848. }
  12849. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12850. {
  12851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12854. {
  12855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12856. }
  12857. else
  12858. {
  12859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12860. }
  12861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12862. isKnowKey = TRUE;
  12863. }
  12864. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12865. {
  12866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12869. {
  12870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12871. }
  12872. else
  12873. {
  12874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12875. }
  12876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12877. isKnowKey = TRUE;
  12878. }
  12879. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12880. {
  12881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12884. {
  12885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12886. }
  12887. else
  12888. {
  12889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12890. }
  12891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12892. isKnowKey = TRUE;
  12893. }
  12894. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12895. {
  12896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12899. {
  12900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12901. }
  12902. else
  12903. {
  12904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12905. }
  12906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12907. isKnowKey = TRUE;
  12908. }
  12909. #if 1
  12910. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12911. {
  12912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12914. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12915. {
  12916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12917. }
  12918. else
  12919. {
  12920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12921. }
  12922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12923. isKnowKey = TRUE;
  12924. }
  12925. #endif
  12926. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12927. {
  12928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12930. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12931. {
  12932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12933. }
  12934. else
  12935. {
  12936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12937. }
  12938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12939. isKnowKey = TRUE;
  12940. }
  12941. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12942. {
  12943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12945. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12946. {
  12947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12948. }
  12949. else
  12950. {
  12951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12952. }
  12953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12954. isKnowKey = TRUE;
  12955. }
  12956. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12957. {
  12958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12960. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12961. {
  12962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12963. }
  12964. else
  12965. {
  12966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12967. }
  12968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12969. isKnowKey = TRUE;
  12970. }
  12971. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12972. {
  12973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12975. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12976. {
  12977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12978. }
  12979. else
  12980. {
  12981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12982. }
  12983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12984. isKnowKey = TRUE;
  12985. }
  12986. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12987. {
  12988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12990. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12991. {
  12992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12993. }
  12994. else
  12995. {
  12996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12997. }
  12998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12999. isKnowKey = TRUE;
  13000. }
  13001. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13002. {
  13003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13005. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13006. {
  13007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13008. }
  13009. else
  13010. {
  13011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13012. }
  13013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13014. isKnowKey = TRUE;
  13015. }
  13016. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13017. {
  13018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13020. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13021. {
  13022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13023. }
  13024. else
  13025. {
  13026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13027. }
  13028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13029. isKnowKey = TRUE;
  13030. }
  13031. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13032. {
  13033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13035. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13036. {
  13037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13038. }
  13039. else
  13040. {
  13041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13042. }
  13043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13044. isKnowKey = TRUE;
  13045. }
  13046. //=========================================================
  13047. if(!isEmpty && !isKnowKey)
  13048. {
  13049. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13050. strcpy(unknownkey[UnknownKeynum], keyReq);
  13051. UnknownKeynum = UnknownKeynum + 1;
  13052. }
  13053. }
  13054. void processUnkownKey(void)
  13055. {
  13056. DEBUG_INFO("processUnkownKey...\n");
  13057. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13058. for(int index=0; index < UnknownKeynum; index++)
  13059. {
  13060. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13061. {
  13062. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13063. }
  13064. }
  13065. }
  13066. int setKeyValue(char *key, char *value)
  13067. {
  13068. int isSuccess = NotSupported;
  13069. int check_ascii=0;
  13070. char str[256]={0};
  13071. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13072. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13073. {
  13074. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13075. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13076. {
  13077. strcpy(str, (const char*)value);
  13078. for(int i = 0; str[i]; i++){
  13079. str[i] = tolower(str[i]);
  13080. }
  13081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13082. isSuccess = ConfigurationStatus_Accepted;
  13083. }
  13084. else
  13085. {
  13086. isSuccess = ConfigurationStatus_Rejected;
  13087. }
  13088. }
  13089. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13090. {
  13091. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13093. {
  13094. strcpy(str, (const char*)value);
  13095. for(int i = 0; str[i]; i++){
  13096. str[i] = tolower(str[i]);
  13097. }
  13098. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13099. isSuccess = ConfigurationStatus_Accepted;
  13100. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13101. }
  13102. else
  13103. {
  13104. isSuccess = ConfigurationStatus_Rejected;
  13105. }
  13106. }
  13107. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13108. {
  13109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13110. {
  13111. strcpy(str, (const char*)value);
  13112. for(int i = 0; str[i]; i++)
  13113. {
  13114. str[i] = tolower(str[i]);
  13115. }
  13116. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13118. isSuccess = ConfigurationStatus_Accepted;
  13119. }
  13120. else
  13121. {
  13122. isSuccess = ConfigurationStatus_Rejected;
  13123. }
  13124. }
  13125. if(strcmp(key, "BlinkRepeat") == 0)
  13126. {
  13127. //Charger.BlinkRepeat = Integer.parseInt(value);
  13128. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13129. {
  13130. check_ascii = value[0];
  13131. if( (check_ascii < 48) || (check_ascii > 57) )
  13132. {
  13133. isSuccess = ConfigurationStatus_Rejected;
  13134. }
  13135. else
  13136. {
  13137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13138. isSuccess = ConfigurationStatus_Accepted;
  13139. }
  13140. }
  13141. else
  13142. {
  13143. isSuccess = ConfigurationStatus_Rejected;
  13144. }
  13145. }
  13146. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13147. {
  13148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13149. {
  13150. check_ascii = value[0];
  13151. if( (check_ascii < 48) || (check_ascii > 57) )
  13152. {
  13153. isSuccess = ConfigurationStatus_Rejected;
  13154. }
  13155. else
  13156. {
  13157. if((atoi(value) == 0) || (atoi(value) >= 10))
  13158. {
  13159. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13161. isSuccess = ConfigurationStatus_Accepted;
  13162. }
  13163. else
  13164. isSuccess = ConfigurationStatus_Rejected;
  13165. }
  13166. }
  13167. else
  13168. {
  13169. isSuccess = ConfigurationStatus_Rejected;
  13170. }
  13171. }
  13172. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13173. {
  13174. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13175. {
  13176. check_ascii = value[0];
  13177. if( (check_ascii < 48) || (check_ascii > 57) )
  13178. {
  13179. isSuccess = ConfigurationStatus_Rejected;
  13180. }
  13181. else
  13182. {
  13183. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13185. isSuccess = ConfigurationStatus_Accepted;
  13186. }
  13187. }
  13188. else
  13189. {
  13190. isSuccess = ConfigurationStatus_Rejected;
  13191. }
  13192. }
  13193. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13194. {
  13195. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13196. {
  13197. check_ascii = value[0];
  13198. if( (check_ascii < 48) || (check_ascii > 57) )
  13199. {
  13200. isSuccess = ConfigurationStatus_Rejected;
  13201. }
  13202. else
  13203. {
  13204. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13206. isSuccess = ConfigurationStatus_Accepted;
  13207. }
  13208. }
  13209. else
  13210. {
  13211. isSuccess = ConfigurationStatus_Rejected;
  13212. }
  13213. }
  13214. if(strcmp(key, "HeartbeatInterval") == 0)
  13215. {
  13216. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13217. {
  13218. check_ascii = value[0];
  13219. if( (check_ascii < 48) || (check_ascii > 57) )
  13220. {
  13221. isSuccess = ConfigurationStatus_Rejected;
  13222. }
  13223. else
  13224. {
  13225. if((atoi(value) == 0) || (atoi(value) >= 10))
  13226. {
  13227. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13229. HeartBeatWaitTime = atoi(value);
  13230. isSuccess = ConfigurationStatus_Accepted;
  13231. }
  13232. else
  13233. {
  13234. isSuccess = ConfigurationStatus_Rejected;
  13235. }
  13236. }
  13237. }
  13238. else
  13239. {
  13240. isSuccess = ConfigurationStatus_Rejected;
  13241. }
  13242. }
  13243. if(strcmp(key, "LightIntensity") == 0)
  13244. {
  13245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13246. {
  13247. check_ascii = value[0];
  13248. if( (check_ascii < 48) || (check_ascii > 57) )
  13249. {
  13250. isSuccess = ConfigurationStatus_Rejected;
  13251. }
  13252. else
  13253. {
  13254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13255. isSuccess = ConfigurationStatus_Accepted;
  13256. }
  13257. }
  13258. else
  13259. {
  13260. isSuccess = ConfigurationStatus_Rejected;
  13261. }
  13262. }
  13263. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13264. {
  13265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13266. {
  13267. strcpy(str, (const char*)value);
  13268. for(int i = 0; str[i]; i++)
  13269. {
  13270. str[i] = tolower(str[i]);
  13271. }
  13272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13273. isSuccess = ConfigurationStatus_Accepted;
  13274. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13275. }
  13276. else
  13277. {
  13278. isSuccess = ConfigurationStatus_Rejected;
  13279. }
  13280. }
  13281. if(strcmp(key, "LocalPreAuthorize") == 0)
  13282. {
  13283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13284. {
  13285. strcpy(str, (const char*)value);
  13286. for(int i = 0; str[i]; i++)
  13287. {
  13288. str[i] = tolower(str[i]);
  13289. }
  13290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13291. isSuccess = ConfigurationStatus_Accepted;
  13292. }
  13293. else
  13294. {
  13295. isSuccess = ConfigurationStatus_Rejected;
  13296. }
  13297. }
  13298. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13299. {
  13300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13301. {
  13302. check_ascii = value[0];
  13303. if( (check_ascii < 48) || (check_ascii > 57) )
  13304. {
  13305. isSuccess = ConfigurationStatus_Rejected;
  13306. }
  13307. else
  13308. {
  13309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13310. isSuccess = ConfigurationStatus_Accepted;
  13311. }
  13312. }
  13313. else
  13314. {
  13315. isSuccess = ConfigurationStatus_Rejected;
  13316. }
  13317. }
  13318. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13319. {
  13320. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13321. {
  13322. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13323. isSuccess = ConfigurationStatus_Accepted;
  13324. }
  13325. else
  13326. {
  13327. isSuccess = ConfigurationStatus_Rejected;
  13328. }
  13329. }
  13330. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13331. {
  13332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13333. {
  13334. check_ascii = value[0];
  13335. if( (check_ascii < 48) || (check_ascii > 57) )
  13336. {
  13337. isSuccess = ConfigurationStatus_Rejected;
  13338. }
  13339. else
  13340. {
  13341. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. }
  13346. else
  13347. {
  13348. isSuccess = ConfigurationStatus_Rejected;
  13349. }
  13350. }
  13351. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13352. {
  13353. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13354. {
  13355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13356. isSuccess = ConfigurationStatus_Accepted;
  13357. }
  13358. else
  13359. {
  13360. isSuccess = ConfigurationStatus_Rejected;
  13361. }
  13362. }
  13363. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13364. {
  13365. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13366. {
  13367. check_ascii = value[0];
  13368. if( (check_ascii < 48) || (check_ascii > 57) )
  13369. {
  13370. isSuccess = ConfigurationStatus_Rejected;
  13371. }
  13372. else
  13373. {
  13374. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13376. isSuccess = ConfigurationStatus_Accepted;
  13377. }
  13378. }
  13379. else
  13380. {
  13381. isSuccess = ConfigurationStatus_Rejected;
  13382. }
  13383. }
  13384. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13385. {
  13386. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13387. {
  13388. check_ascii = value[0];
  13389. if( (check_ascii < 48) || (check_ascii > 57) )
  13390. {
  13391. isSuccess = ConfigurationStatus_Rejected;
  13392. }
  13393. else
  13394. {
  13395. if((atoi(value) == 0) || (atoi(value) >= 10))
  13396. {
  13397. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13399. isSuccess = ConfigurationStatus_Accepted;
  13400. }
  13401. else
  13402. {
  13403. isSuccess = ConfigurationStatus_Rejected;
  13404. }
  13405. }
  13406. }
  13407. else
  13408. {
  13409. isSuccess = ConfigurationStatus_Rejected;
  13410. }
  13411. }
  13412. if(strcmp(key, "MinimumStatusDuration") == 0)
  13413. {
  13414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13415. {
  13416. check_ascii = value[0];
  13417. if( (check_ascii < 48) || (check_ascii > 57) )
  13418. {
  13419. isSuccess = ConfigurationStatus_Rejected;
  13420. }
  13421. else
  13422. {
  13423. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13424. {
  13425. isSuccess = ConfigurationStatus_Rejected;
  13426. }
  13427. else
  13428. {
  13429. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13431. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13432. isSuccess = ConfigurationStatus_Accepted;
  13433. }
  13434. }
  13435. }
  13436. else
  13437. {
  13438. isSuccess = ConfigurationStatus_Rejected;
  13439. }
  13440. }
  13441. if(strcmp(key, "NumberOfConnectors") == 0)
  13442. {
  13443. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13444. {
  13445. check_ascii = value[0];
  13446. if( (check_ascii < 48) || (check_ascii > 57) )
  13447. {
  13448. isSuccess = ConfigurationStatus_Rejected;
  13449. }
  13450. else
  13451. {
  13452. //Charger.ResetRetries = Integer.parseInt(value);
  13453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13454. isSuccess = ConfigurationStatus_Accepted;
  13455. }
  13456. }
  13457. else
  13458. {
  13459. isSuccess = ConfigurationStatus_Rejected;
  13460. }
  13461. }
  13462. if(strcmp(key, "ResetRetries") == 0)
  13463. {
  13464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13465. {
  13466. check_ascii = value[0];
  13467. if( (check_ascii < 48) || (check_ascii > 57) )
  13468. {
  13469. isSuccess = ConfigurationStatus_Rejected;
  13470. }
  13471. else
  13472. {
  13473. //Charger.ResetRetries = Integer.parseInt(value);
  13474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13475. isSuccess = ConfigurationStatus_Accepted;
  13476. }
  13477. }
  13478. else
  13479. {
  13480. isSuccess = ConfigurationStatus_Rejected;
  13481. }
  13482. }
  13483. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13484. {
  13485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13486. {
  13487. strcpy(str, (const char*)value);
  13488. for(int i = 0; str[i]; i++)
  13489. {
  13490. str[i] = tolower(str[i]);
  13491. }
  13492. if(strcmp(str, "notapplicable")== 0)
  13493. {
  13494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13495. isSuccess = ConfigurationStatus_Accepted;
  13496. }
  13497. else if(strcmp(str, "unknown")== 0)
  13498. {
  13499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13500. isSuccess = ConfigurationStatus_Accepted;
  13501. }
  13502. else if(strcmp(str, "rst")== 0)
  13503. {
  13504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13505. isSuccess = ConfigurationStatus_Accepted;
  13506. }
  13507. else if(strcmp(str, "rts")== 0)
  13508. {
  13509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13510. isSuccess = ConfigurationStatus_Accepted;
  13511. }
  13512. else if(strcmp(str, "srt")== 0)
  13513. {
  13514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13515. isSuccess = ConfigurationStatus_Accepted;
  13516. }
  13517. else if(strcmp(str, "str")== 0)
  13518. {
  13519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13520. isSuccess = ConfigurationStatus_Accepted;
  13521. }
  13522. else if(strcmp(str, "trs")== 0)
  13523. {
  13524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13525. isSuccess = ConfigurationStatus_Accepted;
  13526. }
  13527. else if(strcmp(str, "tsr")== 0)
  13528. {
  13529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13530. isSuccess = ConfigurationStatus_Accepted;
  13531. }
  13532. else
  13533. {
  13534. isSuccess = ConfigurationStatus_Rejected;
  13535. }
  13536. }
  13537. else
  13538. {
  13539. isSuccess = ConfigurationStatus_Rejected;
  13540. }
  13541. }
  13542. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13543. {
  13544. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13545. {
  13546. check_ascii = value[0];
  13547. if( (check_ascii < 48) || (check_ascii > 57) )
  13548. {
  13549. isSuccess = ConfigurationStatus_Rejected;
  13550. }
  13551. else
  13552. {
  13553. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13554. isSuccess = ConfigurationStatus_Accepted;
  13555. }
  13556. }
  13557. else
  13558. {
  13559. isSuccess = ConfigurationStatus_Rejected;
  13560. }
  13561. }
  13562. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13563. {
  13564. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13565. {
  13566. strcpy(str, (const char*)value);
  13567. for(int i = 0; str[i]; i++)
  13568. {
  13569. str[i] = tolower(str[i]);
  13570. }
  13571. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13573. isSuccess = ConfigurationStatus_Accepted;
  13574. }
  13575. else
  13576. {
  13577. isSuccess = ConfigurationStatus_Rejected;
  13578. }
  13579. }
  13580. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13581. {
  13582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13583. {
  13584. strcpy(str, (const char*)value);
  13585. for(int i = 0; str[i]; i++)
  13586. {
  13587. str[i] = tolower(str[i]);
  13588. }
  13589. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13591. isSuccess = ConfigurationStatus_Accepted;
  13592. }
  13593. else
  13594. {
  13595. isSuccess = ConfigurationStatus_Rejected;
  13596. }
  13597. }
  13598. if(strcmp(key, "StopTxnAlignedData") == 0)
  13599. {
  13600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13601. {
  13602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13603. isSuccess = ConfigurationStatus_Accepted;
  13604. }
  13605. else
  13606. {
  13607. isSuccess = ConfigurationStatus_Rejected;
  13608. }
  13609. }
  13610. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13611. {
  13612. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13613. {
  13614. check_ascii = value[0];
  13615. if( (check_ascii < 48) || (check_ascii > 57) )
  13616. {
  13617. isSuccess = ConfigurationStatus_Rejected;
  13618. }
  13619. else
  13620. {
  13621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13622. isSuccess = ConfigurationStatus_Accepted;
  13623. }
  13624. }
  13625. else
  13626. {
  13627. isSuccess = ConfigurationStatus_Rejected;
  13628. }
  13629. }
  13630. if(strcmp(key, "StopTxnSampledData") == 0)
  13631. {
  13632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13633. {
  13634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13635. isSuccess = ConfigurationStatus_Accepted;
  13636. }
  13637. else
  13638. {
  13639. isSuccess = ConfigurationStatus_Rejected;
  13640. }
  13641. }
  13642. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13643. {
  13644. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13645. {
  13646. check_ascii = value[0];
  13647. if( (check_ascii < 48) || (check_ascii > 57) )
  13648. {
  13649. isSuccess = ConfigurationStatus_Rejected;
  13650. }
  13651. else
  13652. {
  13653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13654. isSuccess = ConfigurationStatus_Accepted;
  13655. }
  13656. }
  13657. else
  13658. {
  13659. isSuccess = ConfigurationStatus_Rejected;
  13660. }
  13661. }
  13662. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13663. {
  13664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13665. {
  13666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13667. isSuccess = ConfigurationStatus_Accepted;
  13668. }
  13669. else
  13670. {
  13671. isSuccess = ConfigurationStatus_Rejected;
  13672. }
  13673. }
  13674. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13675. {
  13676. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13677. {
  13678. check_ascii = value[0];
  13679. if( (check_ascii < 48) || (check_ascii > 57) )
  13680. {
  13681. isSuccess = ConfigurationStatus_Rejected;
  13682. }
  13683. else
  13684. {
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13686. isSuccess = ConfigurationStatus_Accepted;
  13687. }
  13688. }
  13689. else
  13690. {
  13691. isSuccess = ConfigurationStatus_Rejected;
  13692. }
  13693. }
  13694. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13695. {
  13696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13697. {
  13698. check_ascii = value[0];
  13699. if( (check_ascii < 48) || (check_ascii > 57) )
  13700. {
  13701. isSuccess = ConfigurationStatus_Rejected;
  13702. }
  13703. else
  13704. {
  13705. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13707. TransactionMessageAttemptsValue = atoi(value);
  13708. isSuccess = ConfigurationStatus_Accepted;
  13709. }
  13710. }
  13711. else
  13712. {
  13713. isSuccess = ConfigurationStatus_Rejected;
  13714. }
  13715. }
  13716. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13717. {
  13718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13719. {
  13720. check_ascii = value[0];
  13721. if( (check_ascii < 48) || (check_ascii > 57) )
  13722. {
  13723. isSuccess = ConfigurationStatus_Rejected;
  13724. }
  13725. else
  13726. {
  13727. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13729. TransactionMessageRetryIntervalValue = atoi(value);
  13730. isSuccess = ConfigurationStatus_Accepted;
  13731. }
  13732. }
  13733. else
  13734. {
  13735. isSuccess = ConfigurationStatus_Rejected;
  13736. }
  13737. }
  13738. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13739. {
  13740. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13741. {
  13742. strcpy(str, (const char*)value);
  13743. for(int i = 0; str[i]; i++)
  13744. {
  13745. str[i] = tolower(str[i]);
  13746. }
  13747. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13749. isSuccess = ConfigurationStatus_Accepted;
  13750. }
  13751. else
  13752. {
  13753. isSuccess = ConfigurationStatus_Rejected;
  13754. }
  13755. }
  13756. if(strcmp(key, "WebSocketPingInterval") == 0)
  13757. {
  13758. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13759. {
  13760. check_ascii = value[0];
  13761. if( (check_ascii < 48) || (check_ascii > 57) )
  13762. {
  13763. isSuccess = ConfigurationStatus_Rejected;
  13764. }
  13765. else
  13766. {
  13767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13768. isSuccess = ConfigurationStatus_Accepted;
  13769. }
  13770. }
  13771. else
  13772. {
  13773. isSuccess = ConfigurationStatus_Rejected;
  13774. }
  13775. }
  13776. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13777. {
  13778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13779. {
  13780. strcpy(str, (const char*)value);
  13781. for(int i = 0; str[i]; i++)
  13782. {
  13783. str[i] = tolower(str[i]);
  13784. }
  13785. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13787. isSuccess = ConfigurationStatus_Accepted;
  13788. }
  13789. else
  13790. {
  13791. isSuccess = ConfigurationStatus_Rejected;
  13792. }
  13793. }
  13794. if(strcmp(key, "AuthorizationKey") == 0)
  13795. {
  13796. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13797. {
  13798. strcpy(str, (const char*)value);
  13799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13800. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13801. isSuccess = ConfigurationStatus_Accepted;
  13802. }
  13803. else
  13804. {
  13805. isSuccess = ConfigurationStatus_Rejected;
  13806. }
  13807. }
  13808. if(strcmp(key, "SecurityProfile") == 0)
  13809. {
  13810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13811. {
  13812. check_ascii = value[0];
  13813. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13814. {
  13815. isSuccess = ConfigurationStatus_Rejected;
  13816. }
  13817. else if(check_ascii == 0x33)
  13818. {
  13819. isSuccess = NotSupported;
  13820. }
  13821. else
  13822. {
  13823. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13824. {
  13825. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13826. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13827. isSuccess = ConfigurationStatus_Accepted;
  13828. }
  13829. else
  13830. isSuccess = ConfigurationStatus_Rejected;
  13831. }
  13832. }
  13833. else
  13834. {
  13835. isSuccess = ConfigurationStatus_Rejected;
  13836. }
  13837. }
  13838. if(strcmp(key, "DefaultPrice") == 0)
  13839. {
  13840. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13841. {
  13842. strcpy(str, (const char*)value);
  13843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13844. isSuccess = ConfigurationStatus_Accepted;
  13845. }
  13846. else
  13847. {
  13848. isSuccess = ConfigurationStatus_Rejected;
  13849. }
  13850. }
  13851. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13852. {
  13853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13854. {
  13855. strcpy(str, (const char*)value);
  13856. for(int i = 0; str[i]; i++)
  13857. {
  13858. str[i] = tolower(str[i]);
  13859. }
  13860. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13862. isSuccess = ConfigurationStatus_Accepted;
  13863. }
  13864. else
  13865. {
  13866. isSuccess = ConfigurationStatus_Rejected;
  13867. }
  13868. }
  13869. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13870. {
  13871. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13872. {
  13873. strcpy(str, (const char*)value);
  13874. for(int i = 0; str[i]; i++)
  13875. {
  13876. str[i] = tolower(str[i]);
  13877. }
  13878. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13880. isSuccess = ConfigurationStatus_Accepted;
  13881. }
  13882. else
  13883. {
  13884. isSuccess = ConfigurationStatus_Rejected;
  13885. }
  13886. }
  13887. #if 0
  13888. //For OCPP Test Case
  13889. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13890. {
  13891. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13892. {
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13894. isSuccess = ConfigurationStatus_Accepted;
  13895. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13896. }
  13897. else
  13898. {
  13899. isSuccess = ConfigurationStatus_Rejected;
  13900. }
  13901. }
  13902. #endif
  13903. #if 1
  13904. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13905. {
  13906. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13907. {
  13908. strcpy(str, (const char*)value);
  13909. for(int i = 0; str[i]; i++)
  13910. {
  13911. str[i] = tolower(str[i]);
  13912. }
  13913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13914. isSuccess = ConfigurationStatus_Accepted;
  13915. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13916. }
  13917. else
  13918. {
  13919. isSuccess = ConfigurationStatus_Rejected;
  13920. }
  13921. }
  13922. #endif
  13923. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13924. {
  13925. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13926. {
  13927. check_ascii = value[0];
  13928. if( (check_ascii < 48) || (check_ascii > 57) )
  13929. {
  13930. isSuccess = ConfigurationStatus_Rejected;
  13931. }
  13932. else
  13933. {
  13934. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13935. isSuccess = ConfigurationStatus_Accepted;
  13936. }
  13937. }
  13938. else
  13939. {
  13940. isSuccess = ConfigurationStatus_Rejected;
  13941. }
  13942. }
  13943. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13944. {
  13945. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13946. {
  13947. check_ascii = value[0];
  13948. if( (check_ascii < 48) || (check_ascii > 57) )
  13949. {
  13950. isSuccess = ConfigurationStatus_Rejected;
  13951. }
  13952. else
  13953. {
  13954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13955. isSuccess = ConfigurationStatus_Accepted;
  13956. }
  13957. }
  13958. else
  13959. {
  13960. isSuccess = ConfigurationStatus_Rejected;
  13961. }
  13962. }
  13963. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13964. {
  13965. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13966. {
  13967. strcpy(str, (const char*)value);
  13968. for(int i = 0; str[i]; i++)
  13969. {
  13970. str[i] = tolower(str[i]);
  13971. }
  13972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13973. isSuccess = ConfigurationStatus_Accepted;
  13974. }
  13975. else
  13976. {
  13977. isSuccess = ConfigurationStatus_Rejected;
  13978. }
  13979. }
  13980. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13981. {
  13982. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13983. {
  13984. check_ascii = value[0];
  13985. if( (check_ascii < 48) || (check_ascii > 57) )
  13986. {
  13987. isSuccess = ConfigurationStatus_Rejected;
  13988. }
  13989. else
  13990. {
  13991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13992. isSuccess = ConfigurationStatus_Accepted;
  13993. }
  13994. }
  13995. else
  13996. {
  13997. isSuccess = ConfigurationStatus_Rejected;
  13998. }
  13999. }
  14000. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14001. {
  14002. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14003. {
  14004. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14005. isSuccess = ConfigurationStatus_Accepted;
  14006. }
  14007. else
  14008. {
  14009. isSuccess = ConfigurationStatus_Rejected;
  14010. }
  14011. }
  14012. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14013. {
  14014. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14015. {
  14016. check_ascii = value[0];
  14017. if( (check_ascii < 48) || (check_ascii > 57) )
  14018. {
  14019. isSuccess = ConfigurationStatus_Rejected;
  14020. }
  14021. else
  14022. {
  14023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14024. isSuccess = ConfigurationStatus_Accepted;
  14025. }
  14026. }
  14027. else
  14028. {
  14029. isSuccess = ConfigurationStatus_Rejected;
  14030. }
  14031. }
  14032. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14033. {
  14034. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14035. {
  14036. strcpy(str, (const char*)value);
  14037. for(int i = 0; str[i]; i++)
  14038. {
  14039. str[i] = tolower(str[i]);
  14040. }
  14041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14042. isSuccess = ConfigurationStatus_Accepted;
  14043. }
  14044. else
  14045. {
  14046. isSuccess = ConfigurationStatus_Rejected;
  14047. }
  14048. }
  14049. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14050. {
  14051. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14052. {
  14053. check_ascii = value[0];
  14054. if( (check_ascii < 48) || (check_ascii > 57) )
  14055. {
  14056. isSuccess = ConfigurationStatus_Rejected;
  14057. }
  14058. else
  14059. {
  14060. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14061. isSuccess = ConfigurationStatus_Accepted;
  14062. }
  14063. }
  14064. else
  14065. {
  14066. isSuccess = ConfigurationStatus_Rejected;
  14067. }
  14068. }
  14069. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14070. return isSuccess;
  14071. }
  14072. int TransactionMessageAttemptsGet(void)
  14073. {
  14074. return TransactionMessageAttemptsValue;
  14075. }
  14076. int FirstHeartBeatResponse(void)
  14077. {
  14078. return FirstHeartBeat;
  14079. }
  14080. int TransactionMessageRetryIntervalGet(void)
  14081. {
  14082. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14083. }
  14084. int ReadHttpStatus(int sock)
  14085. {
  14086. //char c;
  14087. char buff[1024]="",*ptr=buff+1;
  14088. int bytes_received, status;
  14089. DEBUG_INFO("Begin Response ..\n");
  14090. while((bytes_received = recv(sock, ptr, 1, 0))){
  14091. if(bytes_received==-1){
  14092. perror("ReadHttpStatus");
  14093. exit(1);
  14094. }
  14095. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14096. ptr++;
  14097. }
  14098. *ptr=0;
  14099. ptr=buff+1;
  14100. sscanf(ptr,"%*s %d ", &status);
  14101. DEBUG_INFO("%s\n",ptr);
  14102. DEBUG_INFO("status=%d\n",status);
  14103. DEBUG_INFO("End Response ..\n");
  14104. return (bytes_received>0)?status:0;
  14105. }
  14106. //the only filed that it parsed is 'Content-Length'
  14107. int ParseHeader(int sock)
  14108. {
  14109. //char c;
  14110. char buff[1024]="",*ptr=buff+4;
  14111. int bytes_received;
  14112. DEBUG_INFO("Begin HEADER ..\n");
  14113. while((bytes_received = recv(sock, ptr, 1, 0))){
  14114. if(bytes_received==-1){
  14115. perror("Parse Header");
  14116. exit(1);
  14117. }
  14118. if(
  14119. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14120. (ptr[-1]=='\r') && (*ptr=='\n' )
  14121. ) break;
  14122. ptr++;
  14123. }
  14124. *ptr=0;
  14125. ptr=buff+4;
  14126. //printf("%s",ptr);
  14127. if(bytes_received){
  14128. ptr=strstr(ptr,"Content-Length:");
  14129. if(ptr){
  14130. sscanf(ptr,"%*s %d",&bytes_received);
  14131. }else
  14132. bytes_received=-1; //unknown size
  14133. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14134. }
  14135. DEBUG_INFO("End HEADER ..\n");
  14136. return bytes_received ;
  14137. }
  14138. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14139. {
  14140. int result = TRUE;
  14141. char rmFileCmd[100]={0};
  14142. char FilePath[100]={0};
  14143. char ftpbuf[200];
  14144. int systemresult;
  14145. //DEBUG_INFO("filename=%s\n",filename);
  14146. //DEBUG_INFO("url=%s\n",url);
  14147. sprintf(FilePath,"/mnt/%s",filename);
  14148. system("ping 8.8.8.8 &");
  14149. if((access(FilePath,F_OK))!=-1)
  14150. {
  14151. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14152. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14153. system(rmFileCmd);
  14154. }
  14155. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14156. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14157. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14158. systemresult = system(ftpbuf);
  14159. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14160. if(systemresult != 0)
  14161. {
  14162. DEBUG_INFO("http DownLoad error!\n");
  14163. result = FALSE;
  14164. }
  14165. system("pkill ping");
  14166. return result;
  14167. }
  14168. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14169. {
  14170. int result = TRUE;
  14171. char rmFileCmd[100]={0};
  14172. char FilePath[100]={0};
  14173. char ftpbuf[200];
  14174. int systemresult;
  14175. //char temp[100];
  14176. sprintf(FilePath,"/mnt/%s",filename);
  14177. system("ping 8.8.8.8 &");
  14178. if((access(FilePath,F_OK))!=-1)
  14179. {
  14180. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14181. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14182. system(rmFileCmd);
  14183. }
  14184. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14185. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14186. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14187. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14188. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14189. systemresult = system(ftpbuf);
  14190. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14191. if(systemresult != 0)
  14192. {
  14193. printf("wget error!\n");
  14194. result = FALSE;
  14195. }
  14196. system("pkill ping");
  14197. return result;
  14198. }
  14199. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14200. {
  14201. char rmFileCmd[100]={0};
  14202. char FilePath[100]={0};
  14203. char buf[512];
  14204. int systemresult = 0;
  14205. //DEBUG_INFO("filename=%s\n",filename);
  14206. //DEBUG_INFO("url=%s\n",url);
  14207. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14208. if((access(FilePath,F_OK))!=-1)
  14209. {
  14210. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14211. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14212. system(rmFileCmd);
  14213. }
  14214. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14215. if(fp == NULL)
  14216. {
  14217. DEBUG_INFO("log is NULL\n");
  14218. return FALSE;
  14219. }
  14220. else
  14221. {
  14222. fprintf(fp, "%s\n", url);
  14223. fprintf(fp, "%s\n", filename);
  14224. fclose(fp);
  14225. }
  14226. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14227. if(phpFP == NULL)
  14228. {
  14229. DEBUG_INFO("PHP upload fail.\n");
  14230. return FALSE;
  14231. }
  14232. else
  14233. {
  14234. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14235. {
  14236. if(strstr(buf, "result") != NULL)
  14237. {
  14238. sscanf(buf, "result: %d", &systemresult);
  14239. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14240. }
  14241. }
  14242. pclose(phpFP);
  14243. }
  14244. if(systemresult != 1)
  14245. {
  14246. DEBUG_INFO("HTTP upload error!\n");
  14247. return FALSE;
  14248. }
  14249. return TRUE;
  14250. }
  14251. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14252. {
  14253. struct hostent* server;
  14254. char *IPbuffer;
  14255. char ftpbuf[200];
  14256. int systemresult;
  14257. // To retrieve host information
  14258. server = gethostbyname(location);
  14259. // To convert an Internet network
  14260. // address into ASCII string
  14261. IPbuffer = inet_ntoa(*((struct in_addr*)
  14262. server->h_addr_list[0]));
  14263. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14264. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14265. /* format : ftpput -u username -p passwd IP target source*/
  14266. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14267. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14268. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14269. systemresult = system(ftpbuf);
  14270. DEBUG_INFO("systemresult=%d\n",systemresult);
  14271. if(systemresult != 0)
  14272. {
  14273. DEBUG_INFO("ftpput error!\n");
  14274. return FALSE;
  14275. }
  14276. return TRUE;
  14277. }
  14278. int GetOcppServerURL()
  14279. {
  14280. int result = FALSE;
  14281. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14282. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14283. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14284. struct yuarel url;
  14285. char urlStr[512];
  14286. // OCPPPH only
  14287. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14288. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14289. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14290. {
  14291. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14292. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14293. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14294. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14295. if(yuarel_parse(&url, urlStr) != -1)
  14296. {
  14297. sprintf(OcppProtocol, "%s", url.scheme);
  14298. sprintf(OcppHost, "%s", url.host);
  14299. if(url.path == NULL)
  14300. OcppTempPath[0] = '\0';
  14301. else
  14302. sprintf(OcppTempPath, "%s", url.path);
  14303. if(url.port == 0)
  14304. {
  14305. if(strcmp(OcppProtocol, "wss") == 0)
  14306. OcppPort = 443;
  14307. else
  14308. OcppPort = 80;
  14309. }
  14310. else
  14311. OcppPort = url.port;
  14312. result = TRUE;
  14313. }
  14314. }
  14315. else
  14316. {
  14317. strcpy(OcppHost,"");
  14318. }
  14319. return result;
  14320. }
  14321. int GetOcppPath()
  14322. {
  14323. int result = FALSE;
  14324. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14325. {
  14326. if(OcppTempPath == NULL)
  14327. {
  14328. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14329. }
  14330. else
  14331. {
  14332. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14333. }
  14334. result = TRUE;
  14335. goto End;
  14336. }
  14337. else
  14338. {
  14339. strcpy(OcppPath,"");
  14340. }
  14341. End:
  14342. return result;
  14343. }
  14344. int GetOcppPort()
  14345. {
  14346. return OcppPort;
  14347. }
  14348. int GetOcppConnStatus(void)
  14349. {
  14350. return ShmOCPP16DataPH->OcppConnStatus;
  14351. }
  14352. void SetOcppConnStatus(uint8_t status)
  14353. {
  14354. ShmOCPP16DataPH->OcppConnStatus = status;
  14355. }
  14356. int GetHeartBeatWithNOResponse(void)
  14357. {
  14358. return HeartBeatWithNOResponse;
  14359. }
  14360. void SetHeartBeatWithNOResponse(void)
  14361. {
  14362. HeartBeatWithNOResponse = 0;
  14363. }
  14364. void GetStartTransactionIdTag(int gun_index)
  14365. {
  14366. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14367. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14368. }
  14369. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14370. {
  14371. char ch;
  14372. FILE *fptr1;
  14373. int temptransactionId;
  14374. char str[100]={0};
  14375. temptransactionId = 0;
  14376. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14377. {
  14378. DEBUG_INFO("IdTag is empty.\n");
  14379. return temptransactionId;
  14380. }
  14381. /*------ Read the file ----------------*/
  14382. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14383. if (!fptr1)
  14384. {
  14385. DEBUG_INFO("QueueTransactionId file open error.\n");
  14386. //printf(" File not found or unable to open the input file!!\n");
  14387. return temptransactionId;
  14388. }
  14389. ch=fgetc(fptr1);
  14390. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14391. rewind(fptr1);
  14392. if(ch!=EOF)
  14393. {
  14394. // printf("%c",ch);
  14395. while (fgets(str, 100, fptr1) != NULL)
  14396. {
  14397. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14398. if(str[0]=='\0')
  14399. {
  14400. break;
  14401. }
  14402. char *revbuf[8] = {0}; // Variable store string split
  14403. int num = 0;// Quantity after string split
  14404. DEBUG_INFO("Transaction queue data= %s\n", str);
  14405. splitstring(str,",",revbuf,&num); // String split
  14406. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14407. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14408. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14409. DEBUG_INFO("------------------------------\n");
  14410. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14411. {
  14412. if(isStopTransaction)
  14413. {
  14414. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14415. {
  14416. temptransactionId = atoi(revbuf[2]);
  14417. //break;
  14418. }
  14419. }
  14420. else
  14421. {
  14422. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14423. {
  14424. temptransactionId = atoi(revbuf[2]);
  14425. //break;
  14426. }
  14427. }
  14428. }
  14429. }
  14430. }
  14431. else
  14432. DEBUG_INFO("EOF\n");
  14433. fclose(fptr1);
  14434. /*------- End of reading ---------------*/
  14435. return temptransactionId;
  14436. }
  14437. void SetTransactionIdZero(int transactionId)
  14438. {
  14439. char ch;
  14440. FILE *fptr1, *fptr2;
  14441. int temptransactionId = 0;
  14442. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14443. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14444. if (!fptr1)
  14445. {
  14446. //printf(" File not found or unable to open the input file!!\n");
  14447. return ;
  14448. }
  14449. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14450. if (!fptr2)
  14451. {
  14452. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14453. fclose(fptr1);
  14454. return ;
  14455. }
  14456. ch=fgetc(fptr1);
  14457. rewind(fptr1);
  14458. if(ch!=EOF)
  14459. {
  14460. // copy all contents to the temporary file except the specific line
  14461. while (fgets(str, 100, fptr1) != NULL)
  14462. {
  14463. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14464. if(str[0]=='\0')
  14465. {
  14466. break;
  14467. }
  14468. char *revbuf[8] = {0};
  14469. int num = 0;
  14470. strcpy(strtemp, str);
  14471. splitstring(str,",",revbuf,&num);
  14472. if(revbuf[2][0] != '\0')
  14473. {
  14474. temptransactionId = atoi(revbuf[2]);
  14475. if(transactionId != temptransactionId)
  14476. {
  14477. fprintf(fptr2, "%s\n", strtemp);
  14478. }
  14479. }
  14480. }
  14481. }
  14482. fclose(fptr1);
  14483. fclose(fptr2);
  14484. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14485. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14486. /*------ Read the file ----------------*/
  14487. }
  14488. int InternetDisconnect(void)
  14489. {
  14490. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14491. }
  14492. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14493. void storeTempStopTransaction(int gun_index)
  14494. {
  14495. char guid[37]={0};
  14496. int tempIndex = 0;
  14497. char TempStopTransaction[256];
  14498. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14499. DEBUG_INFO("storeTempStopTransaction...\n");
  14500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14501. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14502. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14503. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14504. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14505. {
  14506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14507. {
  14508. tempIndex = ((gun_index==2) ? 1: 0);
  14509. }
  14510. else
  14511. {
  14512. tempIndex = gun_index;
  14513. }
  14514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14515. {
  14516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14517. {
  14518. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14519. }
  14520. }// END OF CHAdeMO_QUANTITY
  14521. }
  14522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14523. {
  14524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14525. {
  14526. tempIndex = ((gun_index==2) ? 1: 0);
  14527. }
  14528. else
  14529. {
  14530. tempIndex = gun_index;
  14531. }
  14532. for (int index = 0; index < CCS_QUANTITY; index++)
  14533. {
  14534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14535. {
  14536. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14537. }
  14538. }// END OF CCS_QUANTITY
  14539. }
  14540. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14541. {
  14542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14543. {
  14544. tempIndex = ((gun_index==2) ? 1: 0);
  14545. }
  14546. else
  14547. {
  14548. tempIndex = gun_index;
  14549. }
  14550. for (int index = 0; index < GB_QUANTITY; index++)
  14551. {
  14552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14553. {
  14554. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14555. }
  14556. }// END OF GB_QUANTITY
  14557. }
  14558. else if(gunType[gun_index] == GUN_TYPE_DO)
  14559. {
  14560. tempIndex = gun_index;
  14561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14562. {
  14563. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14564. {
  14565. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14566. }
  14567. }
  14568. }
  14569. else
  14570. {
  14571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14572. {
  14573. tempIndex = 2;
  14574. }
  14575. else
  14576. {
  14577. tempIndex = gun_index;
  14578. }
  14579. for (int index = 0; index < AC_QUANTITY; index++)
  14580. {
  14581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14582. {
  14583. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14584. }
  14585. }// END OF AC_QUANTITY
  14586. }
  14587. //Stop Transaction Time
  14588. struct timeval tmnow;
  14589. struct tm *tm;
  14590. char buf[28];//, usec_buf[6];
  14591. gettimeofday(&tmnow, NULL);
  14592. time_t t;
  14593. t = time(NULL);
  14594. /*UTC time and date*/
  14595. tm = gmtime(&t);
  14596. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14598. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14600. random_uuid(guid);
  14601. /***********************************transactionData******************************************************/
  14602. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14604. //=================================
  14605. //1. Transaction_Begin
  14606. //=================================
  14607. //============================== Energy.Active.Import.Interval ===========================================
  14608. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14609. {
  14610. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  14614. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14615. 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))
  14616. {
  14617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14618. }
  14619. else
  14620. {
  14621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14622. }
  14623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14625. }
  14626. //=================================
  14627. //2. Transaction_End
  14628. //=================================
  14629. //2.1====================================== Current.Import L1 ==============================================
  14630. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14631. {
  14632. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14633. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14634. {
  14635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14636. {
  14637. tempIndex = ((gun_index==2) ? 1: 0);
  14638. }
  14639. else
  14640. {
  14641. tempIndex = gun_index;
  14642. }
  14643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14644. {
  14645. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14646. {
  14647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14648. }
  14649. }// End of for CHAdeMO_QUANTITY
  14650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14651. }
  14652. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14653. {
  14654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14655. {
  14656. tempIndex = ((gun_index==2) ? 1: 0);
  14657. }
  14658. else
  14659. {
  14660. tempIndex = gun_index;
  14661. }
  14662. for (int index = 0; index < CCS_QUANTITY; index++)
  14663. {
  14664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14665. {
  14666. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14667. }
  14668. }// End of for CCS_QUANTITY
  14669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14670. }
  14671. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14672. {
  14673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14674. {
  14675. tempIndex = ((gun_index==2) ? 1: 0);
  14676. }
  14677. else
  14678. {
  14679. tempIndex = gun_index;
  14680. }
  14681. for (int index = 0; index < GB_QUANTITY; index++)
  14682. {
  14683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14684. {
  14685. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14686. }
  14687. }// End of for GB_QUANTITY
  14688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14689. }
  14690. else if(gunType[gun_index] == GUN_TYPE_DO)
  14691. {
  14692. tempIndex = gun_index;
  14693. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14694. {
  14695. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14696. {
  14697. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14698. }
  14699. }
  14700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14701. }
  14702. else
  14703. {
  14704. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14705. {
  14706. tempIndex = 2;
  14707. }
  14708. else
  14709. {
  14710. tempIndex = gun_index;
  14711. }
  14712. for (int index = 0; index < AC_QUANTITY; index++)
  14713. {
  14714. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14715. {
  14716. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14717. }
  14718. }// End of for AC_QUANTITY
  14719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14720. }
  14721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14722. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14723. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14724. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14727. }
  14728. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14729. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14730. {
  14731. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14732. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14733. {
  14734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14735. {
  14736. tempIndex = ((gun_index==2) ? 1: 0);
  14737. }
  14738. else
  14739. {
  14740. tempIndex = gun_index;
  14741. }
  14742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14743. {
  14744. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14745. {
  14746. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14747. }
  14748. }// END OF CHAdeMO_QUANTITY
  14749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14750. }
  14751. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14752. {
  14753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14754. {
  14755. tempIndex = ((gun_index==2) ? 1: 0);
  14756. }
  14757. else
  14758. {
  14759. tempIndex = gun_index;
  14760. }
  14761. for (int index = 0; index < CCS_QUANTITY; index++)
  14762. {
  14763. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14764. {
  14765. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14766. }
  14767. }// END OF CCS_QUANTITY
  14768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14769. }
  14770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14771. {
  14772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14773. {
  14774. tempIndex = ((gun_index==2) ? 1: 0);
  14775. }
  14776. else
  14777. {
  14778. tempIndex = gun_index;
  14779. }
  14780. for (int index = 0; index < GB_QUANTITY; index++)
  14781. {
  14782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14783. {
  14784. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14785. }
  14786. }// END OF GB_QUANTITY
  14787. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14788. }
  14789. else if(gunType[gun_index] == GUN_TYPE_DO)
  14790. {
  14791. tempIndex = gun_index;
  14792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14793. {
  14794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14795. {
  14796. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14797. }
  14798. }
  14799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14800. }
  14801. else
  14802. {
  14803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14804. {
  14805. tempIndex = 2;
  14806. }
  14807. else
  14808. {
  14809. tempIndex = gun_index;
  14810. }
  14811. for (int index = 0; index < AC_QUANTITY; index++)
  14812. {
  14813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14814. {
  14815. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14816. }
  14817. }// END OF AC_QUANTITY
  14818. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14819. }
  14820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14821. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14823. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14826. }
  14827. //2.3====================================== Power.Active.Import =========================================
  14828. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14829. {
  14830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14831. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14832. {
  14833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14834. {
  14835. tempIndex = ((gun_index==2) ? 1: 0);
  14836. }
  14837. else
  14838. {
  14839. tempIndex = gun_index;
  14840. }
  14841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14842. {
  14843. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14844. {
  14845. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14846. }
  14847. } // End for CHAdeMO_QUANTITY
  14848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14849. }
  14850. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14851. {
  14852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14853. {
  14854. tempIndex = ((gun_index==2) ? 1: 0);
  14855. }
  14856. else
  14857. {
  14858. tempIndex = gun_index;
  14859. }
  14860. for (int index = 0; index < CCS_QUANTITY; index++)
  14861. {
  14862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14863. {
  14864. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14865. }
  14866. } // END for CCS_QUANTITY
  14867. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14868. }
  14869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14870. {
  14871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14872. {
  14873. tempIndex = ((gun_index==2) ? 1: 0);
  14874. }
  14875. else
  14876. {
  14877. tempIndex = gun_index;
  14878. }
  14879. for (int index = 0; index < GB_QUANTITY; index++)
  14880. {
  14881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14882. {
  14883. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14884. }
  14885. }// END for GB_QUANTITY
  14886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14887. }
  14888. else if(gunType[gun_index] == GUN_TYPE_DO)
  14889. {
  14890. tempIndex = gun_index;
  14891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14892. {
  14893. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14894. {
  14895. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14896. }
  14897. }
  14898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14899. }
  14900. else
  14901. {
  14902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14903. {
  14904. tempIndex = 2;
  14905. }
  14906. else
  14907. {
  14908. tempIndex = gun_index;
  14909. }
  14910. for (int index = 0; index < AC_QUANTITY; index++)
  14911. {
  14912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14913. {
  14914. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14915. }
  14916. } // END for AC_QUANTITY
  14917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14918. }
  14919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14922. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14925. }
  14926. //2.4====================================== Voltage L1 ====================================================
  14927. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14928. {
  14929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14931. {
  14932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14933. {
  14934. tempIndex = ((gun_index==2) ? 1: 0);
  14935. }
  14936. else
  14937. {
  14938. tempIndex = gun_index;
  14939. }
  14940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14941. {
  14942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14943. {
  14944. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14945. }
  14946. } // END OF FOR CHAdeMO_QUANTITY
  14947. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14948. }
  14949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14950. {
  14951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14952. {
  14953. tempIndex = ((gun_index==2) ? 1: 0);
  14954. }
  14955. else
  14956. {
  14957. tempIndex = gun_index;
  14958. }
  14959. for (int index = 0; index < CCS_QUANTITY; index++)
  14960. {
  14961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14962. {
  14963. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14964. }
  14965. } // END OF FOR CCS_QUANTITY
  14966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14967. }
  14968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14969. {
  14970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14971. {
  14972. tempIndex = ((gun_index==2) ? 1: 0);
  14973. }
  14974. else
  14975. {
  14976. tempIndex = gun_index;
  14977. }
  14978. for (int index = 0; index < GB_QUANTITY; index++)
  14979. {
  14980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14981. {
  14982. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14983. }
  14984. } // END OF FOR GB_QUANTITY
  14985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14986. }
  14987. else if(gunType[gun_index] == GUN_TYPE_DO)
  14988. {
  14989. tempIndex = gun_index;
  14990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14991. {
  14992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14993. {
  14994. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14995. }
  14996. }
  14997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14998. }
  14999. else
  15000. {
  15001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15002. {
  15003. tempIndex = 2;
  15004. }
  15005. else
  15006. {
  15007. tempIndex = gun_index;
  15008. }
  15009. for (int index = 0; index < AC_QUANTITY; index++)
  15010. {
  15011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15012. {
  15013. 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
  15014. }
  15015. } // END OF FOR AC_QUANTITY
  15016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15017. }
  15018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15021. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15024. }
  15025. //2.5============================================== End SoC =========================================================
  15026. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15027. {
  15028. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15029. 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))
  15030. {
  15031. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15032. {
  15033. tempIndex = ((gun_index==2) ? 1: 0);
  15034. }
  15035. else
  15036. {
  15037. tempIndex = gun_index;
  15038. }
  15039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15040. {
  15041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15042. {
  15043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15044. {
  15045. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15046. }
  15047. }
  15048. }
  15049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15050. {
  15051. for (int index = 0; index < CCS_QUANTITY; index++)
  15052. {
  15053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15054. {
  15055. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15056. }
  15057. }
  15058. }
  15059. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15060. {
  15061. for (int index = 0; index < GB_QUANTITY; index++)
  15062. {
  15063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15064. {
  15065. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15066. }
  15067. }
  15068. }
  15069. else if(gunType[gun_index] == GUN_TYPE_DO)
  15070. {
  15071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15072. {
  15073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15074. {
  15075. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15076. }
  15077. }
  15078. }
  15079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15085. } // END FOR DC CASE
  15086. }
  15087. //2.6====================================== Current.Import L2 ==============================================
  15088. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15089. {
  15090. // AC 3 phase L2 current
  15091. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15092. {
  15093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15094. {
  15095. tempIndex = 2;
  15096. }
  15097. else
  15098. {
  15099. tempIndex = gun_index;
  15100. }
  15101. for (int index = 0; index < AC_QUANTITY; index++)
  15102. {
  15103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15104. {
  15105. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15106. }
  15107. }// End of for AC_QUANTITY
  15108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15109. }
  15110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15115. }
  15116. //2.7====================================== Current.Import L3 ==============================================
  15117. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15118. {
  15119. // AC 3 phase L3 current
  15120. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15121. {
  15122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15123. {
  15124. tempIndex = 2;
  15125. }
  15126. else
  15127. {
  15128. tempIndex = gun_index;
  15129. }
  15130. for (int index = 0; index < AC_QUANTITY; index++)
  15131. {
  15132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15133. {
  15134. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15135. }
  15136. }// End of for AC_QUANTITY
  15137. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15138. }
  15139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15144. }
  15145. //2.9====================================== Voltage L2 ====================================================
  15146. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15147. {
  15148. // AC 3 phase L2 volatge
  15149. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15150. {
  15151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15152. {
  15153. tempIndex = 2;
  15154. }
  15155. else
  15156. {
  15157. tempIndex = gun_index;
  15158. }
  15159. for (int index = 0; index < AC_QUANTITY; index++)
  15160. {
  15161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15162. {
  15163. 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
  15164. }
  15165. } // END OF FOR AC_QUANTITY
  15166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15167. }
  15168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15173. }
  15174. //2.10====================================== Voltage L3 ====================================================
  15175. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15176. {
  15177. // AC 3 phase L3 volatge
  15178. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15179. {
  15180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15181. {
  15182. tempIndex = 2;
  15183. }
  15184. else
  15185. {
  15186. tempIndex = gun_index;
  15187. }
  15188. for (int index = 0; index < AC_QUANTITY; index++)
  15189. {
  15190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15191. {
  15192. 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
  15193. }
  15194. } // END OF FOR AC_QUANTITY
  15195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15196. }
  15197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15202. }
  15203. //====================== Start SoC ================================
  15204. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15205. {
  15206. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15207. 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))
  15208. {
  15209. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15210. {
  15211. tempIndex = ((gun_index==2) ? 1: 0);
  15212. }
  15213. else
  15214. {
  15215. tempIndex = gun_index;
  15216. }
  15217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15218. {
  15219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15220. {
  15221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15222. {
  15223. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15224. }
  15225. }
  15226. }
  15227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15228. {
  15229. for (int index = 0; index < CCS_QUANTITY; index++)
  15230. {
  15231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15232. {
  15233. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15234. }
  15235. }
  15236. }
  15237. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15238. {
  15239. for (int index = 0; index < GB_QUANTITY; index++)
  15240. {
  15241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15242. {
  15243. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15244. }
  15245. }
  15246. }
  15247. else if(gunType[gun_index] == GUN_TYPE_DO)
  15248. {
  15249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15250. {
  15251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15252. {
  15253. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15254. }
  15255. }
  15256. }
  15257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15263. } // END FOR DC CASE
  15264. }
  15265. //======================================== Message create ==============================================
  15266. json_object *StopTransaction = json_object_new_object();
  15267. json_object *transactionDatas = json_object_new_array();
  15268. json_object *sampledValues = json_object_new_array();
  15269. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15270. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15271. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15272. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15273. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15274. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15275. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15276. {
  15277. json_object *transactionData = json_object_new_object();
  15278. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15279. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15280. {
  15281. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15282. {
  15283. json_object *sampledValue = json_object_new_object();
  15284. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15285. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15286. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15287. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15288. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15289. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15290. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15291. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15292. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15293. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15294. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15295. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15296. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15297. json_object_array_add(sampledValues, sampledValue);
  15298. }
  15299. }
  15300. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15301. json_object_array_add(transactionDatas, transactionData);
  15302. }
  15303. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15304. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15305. ,MESSAGE_TYPE_CALL
  15306. ,guid
  15307. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15308. json_object_put(StopTransaction);
  15309. // Check File "TempStopTransaction" Exist
  15310. if((access(TempStopTransaction,F_OK))!=-1)
  15311. {
  15312. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15313. fclose(fopen(TempStopTransaction, "w"));
  15314. }
  15315. else
  15316. {
  15317. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15318. FILE *log = fopen(TempStopTransaction, "w+");
  15319. if(log == NULL)
  15320. {
  15321. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15322. return ;
  15323. }
  15324. else
  15325. {
  15326. fclose(log);
  15327. }
  15328. }
  15329. //Add TempStopTransaction | Update TempStopTransaction
  15330. // open file for writing
  15331. FILE *outfile;
  15332. outfile = fopen (TempStopTransaction, "a");
  15333. //DEBUG_INFO("data = %s\n", queuedata);
  15334. fputs(queuedata, outfile);
  15335. fputs("\n", outfile);
  15336. fclose (outfile);
  15337. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15338. }
  15339. void checkTempStopTransaction(int gun_index)
  15340. {
  15341. FILE *fptr1;
  15342. char ch;
  15343. char str[QUEUE_MESSAGE_LENGTH]={0};
  15344. char guid[37]={0};
  15345. char tempdata[65]={0};
  15346. char connectorStr[2]={0};
  15347. char TempStopTransaction[256];
  15348. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15349. fptr1 = fopen(TempStopTransaction, "r");
  15350. //TempStopTransaction格式: 槍號,StopTransaction封包
  15351. if (!fptr1)
  15352. {
  15353. //printf(" File not found or unable to open the input file!!\n");
  15354. return ;
  15355. }
  15356. ch=fgetc(fptr1);
  15357. //printf(" Now the content of the file %s is : \n",fname);
  15358. rewind(fptr1);
  15359. if(ch!=EOF)
  15360. {
  15361. // copy all contents to the temporary file except the specific line
  15362. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15363. {
  15364. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15365. if(str[0]=='\0')
  15366. {
  15367. break;
  15368. }
  15369. //TempStopTransaction格式: 槍號,StopTransaction封包
  15370. strncpy(connectorStr, str, 1);
  15371. if(atoi(connectorStr) != (gun_index+1))
  15372. {
  15373. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15374. fclose(fptr1);
  15375. return ;
  15376. }
  15377. //random_uuid(guid);
  15378. strncpy(guid, str+6, 36); //copy guid
  15379. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15380. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15381. {
  15382. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15383. }
  15384. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15385. OCPP_insert_transaction_msg(NO, str);
  15386. memset(str,0,ARRAY_SIZE(str));
  15387. }
  15388. }
  15389. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15390. fclose(fptr1);
  15391. remove(TempStopTransaction); // remove the original file
  15392. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15393. }
  15394. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15395. {
  15396. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15397. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15398. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15399. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15400. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15401. }
  15402. int GetWebSocketPingInterval(void)
  15403. {
  15404. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15405. }
  15406. int GetServerSign(void)
  15407. {
  15408. return server_sign;
  15409. }
  15410. uint8_t GetOcppSecurityProfile()
  15411. {
  15412. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15413. }
  15414. void GetOcppChargerBoxId(uint8_t *data)
  15415. {
  15416. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15417. }
  15418. void GetOcppSecurityPassword(uint8_t *data)
  15419. {
  15420. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15421. }
  15422. void SetOcppVersion(uint8_t *version)
  15423. {
  15424. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15425. DEBUG_INFO("ocpp version: %s\n", version);
  15426. if(strstr((char*)version, "ocpp1.6") != NULL)
  15427. {
  15428. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15429. }
  15430. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15431. {
  15432. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15433. system("pkill OcppBackend");
  15434. }
  15435. }
  15436. void SetServerSign(int value)
  15437. {
  15438. server_sign = value;
  15439. }
  15440. int GetBootNotificationInterval(void)
  15441. {
  15442. return BootNotificationInterval;
  15443. }
  15444. int GetInternetConn(void)
  15445. {
  15446. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15447. }
  15448. int GetBackendConnectionTimeout(void)
  15449. {
  15450. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15451. }
  15452. int isConnectorInitMode(int gun_index)
  15453. {
  15454. int tempIndex = 0;
  15455. int result = TRUE;
  15456. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15457. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15458. {
  15459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15460. {
  15461. tempIndex = ((gun_index==2) ? 1: 0);
  15462. }
  15463. else
  15464. {
  15465. tempIndex = gun_index;
  15466. }
  15467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15468. {
  15469. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15470. {
  15471. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15472. } //end of the same index
  15473. }//end of for CHAdeMO_QUANTITY
  15474. }
  15475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15476. {
  15477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15478. {
  15479. tempIndex = ((gun_index==2) ? 1: 0);
  15480. }
  15481. else
  15482. {
  15483. tempIndex = gun_index;
  15484. }
  15485. for (int index = 0; index < CCS_QUANTITY; index++)
  15486. {
  15487. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15488. {
  15489. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15490. } //end of the same index
  15491. } // end of for CCS_QUANTITY
  15492. }
  15493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15494. {
  15495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15496. {
  15497. tempIndex = ((gun_index==2) ? 1: 0);
  15498. }
  15499. else
  15500. {
  15501. tempIndex = gun_index;
  15502. }
  15503. for (int index = 0; index < GB_QUANTITY; index++)
  15504. {
  15505. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15506. {
  15507. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15508. } //end of the same index
  15509. } // end of for GB_QUANTITY
  15510. }
  15511. else if(gunType[gun_index] == GUN_TYPE_DO)
  15512. {
  15513. tempIndex = gun_index;
  15514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15515. {
  15516. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15517. {
  15518. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15519. } //end of the same index
  15520. }
  15521. }
  15522. else
  15523. {
  15524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15525. {
  15526. tempIndex = 2;
  15527. }
  15528. else
  15529. {
  15530. tempIndex = gun_index;
  15531. }
  15532. for (int index = 0; index < AC_QUANTITY; index++)
  15533. {
  15534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15535. {
  15536. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15537. }//end of the same index
  15538. }//end of for AC_QUANTITY
  15539. }
  15540. return result;
  15541. }
  15542. void refreshProcDogTimer()
  15543. {
  15544. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15545. }
  15546. void InitialSystemValue(void)
  15547. {
  15548. int connectorIndex = 0;
  15549. //int valueASCII = 0;
  15550. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15551. gunTotalNumber=0;
  15552. SystemInitial = 0;
  15553. locallistVersion=0;
  15554. BootNotificationInterval = 0;
  15555. authorizeRetryTimes = 0;
  15556. GunStatusInterval = 10;
  15557. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15558. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15559. //Hear Beat
  15560. HeartBeatWithNOResponse = 0;
  15561. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15562. FirstHeartBeat = 0;
  15563. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15565. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15566. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15567. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15568. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15569. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15570. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15571. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15572. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15573. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15574. memset(gunType, 0, ARRAY_SIZE(gunType));
  15575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15576. {
  15577. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15578. {
  15579. // DO series
  15580. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15581. {
  15582. SystemInitial = SystemInitial + 1;
  15583. gunTotalNumber = gunTotalNumber + 1;
  15584. gunType[connectorIndex] = GUN_TYPE_DO;
  15585. connectorIndex = connectorIndex + 1;
  15586. }
  15587. }
  15588. else
  15589. {
  15590. // DM, DW, DS series
  15591. //check connector / socket type (index: 8, 9, 10)
  15592. for(int index=7; index <10 ; index++)
  15593. {
  15594. if(index != 8)
  15595. {
  15596. // DC Connector
  15597. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15598. {
  15599. SystemInitial = SystemInitial + 1;
  15600. gunTotalNumber = gunTotalNumber + 1;
  15601. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15602. connectorIndex = connectorIndex + 1;
  15603. }
  15604. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15605. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15606. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15607. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15608. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15609. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15610. {
  15611. SystemInitial = SystemInitial + 1;
  15612. gunTotalNumber = gunTotalNumber + 1;
  15613. gunType[connectorIndex] = GUN_TYPE_CCS;
  15614. connectorIndex = connectorIndex + 1;
  15615. }
  15616. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15617. {
  15618. SystemInitial = SystemInitial + 1;
  15619. gunTotalNumber = gunTotalNumber + 1;
  15620. gunType[connectorIndex] = GUN_TYPE_GBT;
  15621. connectorIndex = connectorIndex + 1;
  15622. }
  15623. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15624. {
  15625. SystemInitial = SystemInitial + 1;
  15626. gunTotalNumber = gunTotalNumber + 1;
  15627. gunType[connectorIndex] = GUN_TYPE_DO;
  15628. connectorIndex = connectorIndex + 1;
  15629. }
  15630. }
  15631. else
  15632. {
  15633. // AC Connector
  15634. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15635. {
  15636. SystemInitial = SystemInitial + 1;
  15637. gunTotalNumber = gunTotalNumber + 1;
  15638. gunType[connectorIndex] = GUN_TYPE_AC;
  15639. connectorIndex = connectorIndex + 1;
  15640. }
  15641. }
  15642. }
  15643. }
  15644. //DEBUG_INFO("DC ...\n");
  15645. }
  15646. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15647. {
  15648. //check connector / socket type (index: 8, 9, 10)
  15649. for(int index=7; index <10 ; index++)
  15650. {
  15651. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15652. {
  15653. SystemInitial = SystemInitial + 1;
  15654. gunTotalNumber = gunTotalNumber + 1;
  15655. gunType[connectorIndex] = GUN_TYPE_AC;
  15656. connectorIndex = connectorIndex + 1;
  15657. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15658. }
  15659. }
  15660. }
  15661. //Status && ConnectorPlugIn Setting
  15662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15663. {
  15664. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15665. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15666. }
  15667. for (int index = 0; index < CCS_QUANTITY; index++)
  15668. {
  15669. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15670. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15671. }
  15672. for (int index = 0; index < GB_QUANTITY; index++)
  15673. {
  15674. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15675. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15676. }
  15677. for (int index = 0; index < AC_QUANTITY; index++)
  15678. {
  15679. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15680. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15681. }
  15682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15683. {
  15684. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15685. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15686. }
  15687. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15688. {
  15689. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15690. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15691. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15692. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15693. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15694. }
  15695. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15696. clientTime.Heartbeat=time((time_t*)NULL);
  15697. sleep(1);
  15698. }
  15699. void LWS_Send(char *str)
  15700. {
  15701. //=====================================================
  15702. // Check InternetConn 0: disconnected, 1: connected
  15703. //====================================================
  15704. if(GetOcppConnStatus() == 0)
  15705. {
  15706. DEBUG_INFO("offline now !!!\n");
  15707. return;
  15708. }
  15709. // Only disable isWebsocketSendable operation initiated by charger
  15710. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15711. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15712. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15713. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15714. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15715. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15716. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15717. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15718. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15719. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15720. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15721. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15722. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15723. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15724. {
  15725. isWebsocketSendable = 0;
  15726. }
  15727. pthread_mutex_lock(&lock_send);
  15728. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15729. sprintf((char *)SendBuffer, "%s", str);
  15730. SendBufLen = strlen(str);
  15731. pthread_mutex_unlock(&lock_send);
  15732. lws_callback_on_writable(wsi_client);
  15733. //lws_service(context, 0);
  15734. //sleep(1);
  15735. }
  15736. void LWS_SendNow(char *str)
  15737. {
  15738. //=====================================================
  15739. // Check InternetConn 0: disconnected, 1: connected
  15740. //====================================================
  15741. if(GetOcppConnStatus() == 0)
  15742. {
  15743. DEBUG_INFO("offline now !!!\n");
  15744. return;
  15745. }
  15746. // Only disable isWebsocketSendable operation initiated by charger
  15747. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15748. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15749. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15750. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15751. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15752. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15753. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15754. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15755. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15756. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15757. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15758. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15759. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15760. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15761. {
  15762. isWebsocketSendable = 0;
  15763. }
  15764. pthread_mutex_lock(&lock_send);
  15765. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15766. sprintf((char *)SendBuffer, "%s", str);
  15767. SendBufLen = strlen(str);
  15768. pthread_mutex_unlock(&lock_send);
  15769. lws_callback_on_writable(wsi_client);
  15770. lws_service(context, 0);
  15771. //sleep(1);
  15772. }