MessageHandler.c 832 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010
  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 InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  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 isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. 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);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. 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);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. 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));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. 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);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. 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);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. 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) &&
  836. (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))
  837. {
  838. //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);
  839. //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);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct ParsingResult
  861. {
  862. int result;
  863. int scanedElement;
  864. int year;
  865. int month;
  866. int mday;
  867. int hour;
  868. int min;
  869. int sec;
  870. int tz_hour;
  871. int tz_min;
  872. float minSec;
  873. }parsingResult;
  874. struct tm tmStart;
  875. struct timeb tbStart;
  876. if(strstr((char*)start, ".") != NULL)
  877. {
  878. // Original data with mini second
  879. if(strstr((char*)start, "Z") != NULL)
  880. {
  881. // Original data with Z
  882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  883. &parsingResult.year,
  884. &parsingResult.month,
  885. &parsingResult.mday,
  886. &parsingResult.hour,
  887. &parsingResult.min,
  888. &parsingResult.sec,
  889. &parsingResult.minSec);
  890. }
  891. else
  892. {
  893. // Original data without Z
  894. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  895. &parsingResult.year,
  896. &parsingResult.month,
  897. &parsingResult.mday,
  898. &parsingResult.hour,
  899. &parsingResult.min,
  900. &parsingResult.sec,
  901. &parsingResult.minSec,
  902. &parsingResult.tz_hour,
  903. &parsingResult.tz_min);
  904. }
  905. }
  906. else
  907. {
  908. // Original data without mini second
  909. if(strstr((char*)start, "Z") != NULL)
  910. {
  911. // Original data with Z
  912. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  913. &parsingResult.year,
  914. &parsingResult.month,
  915. &parsingResult.mday,
  916. &parsingResult.hour,
  917. &parsingResult.min,
  918. &parsingResult.sec);
  919. }
  920. else
  921. {
  922. // Original data without Z
  923. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  924. &parsingResult.year,
  925. &parsingResult.month,
  926. &parsingResult.mday,
  927. &parsingResult.hour,
  928. &parsingResult.min,
  929. &parsingResult.sec,
  930. &parsingResult.tz_hour,
  931. &parsingResult.tz_min);
  932. }
  933. }
  934. if(parsingResult.scanedElement >= 6)
  935. {
  936. tmStart.tm_year = parsingResult.year - 1900;
  937. tmStart.tm_mon = parsingResult.month - 1;
  938. tmStart.tm_mday = parsingResult.mday;
  939. tmStart.tm_hour = parsingResult.hour;
  940. tmStart.tm_min = parsingResult.min;
  941. tmStart.tm_sec = parsingResult.sec;
  942. tmStart.tm_gmtoff = 0;
  943. tbStart.time = mktime(&tmStart);
  944. tbStart.timezone = 0;
  945. tbStart.millitm = 0;
  946. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  947. if(DiffTimebWithNowSec(tbStart) <= 0)
  948. result = NO;
  949. else
  950. result = YES;
  951. }
  952. else
  953. {
  954. DEBUG_WARN("Start date parsing error.\n");
  955. }
  956. return result;
  957. }
  958. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  959. {
  960. int result = -1;
  961. struct tm tmStart;
  962. struct timeb tbStart;
  963. struct tm tmStop;
  964. struct timeb tbStop;
  965. 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) &&
  966. (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))
  967. {
  968. tmStart.tm_year -= 1900;
  969. tmStart.tm_mon -= 1;
  970. tbStart.time = mktime(&tmStart);
  971. tbStart.millitm = 0;
  972. tmStop.tm_year -= 1900;
  973. tmStop.tm_mon -= 1;
  974. tbStop.time = mktime(&tmStop);
  975. tbStop.millitm = 0;
  976. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  977. }
  978. return result;
  979. }
  980. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  981. {
  982. FILE *fp;
  983. char profileFileName[128];
  984. char *line = NULL;
  985. size_t len = 0;
  986. time_t CurrentTime;
  987. struct tm *tmComposite;
  988. struct StructChargingProfile maxProfile;
  989. uint8_t limitMax=0;
  990. int compositePeriodIdx = 0;
  991. CurrentTime = time(NULL);
  992. tmComposite=localtime(&CurrentTime);
  993. 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);
  994. if(isUnitA)
  995. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  996. else
  997. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  998. compositeProfile->ChargingSchedule.Duration = durationReq;
  999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1000. {
  1001. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1004. }
  1005. compositeProfile->ChargingProfileId = 0;
  1006. compositeProfile->StackLevel = 99 ;
  1007. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1008. maxProfile.ChargingProfileId = -1;
  1009. maxProfile.ChargingSchedule.Duration = -1;
  1010. system("rm -f /tmp/*.json");
  1011. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1012. // Search max profile
  1013. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1014. if((access(profileFileName, F_OK))!=-1)
  1015. {
  1016. fp = fopen(profileFileName, "r");
  1017. while(getline(&line, &len, fp) != -1)
  1018. {
  1019. json_object *obj = NULL;
  1020. obj = json_tokener_parse(line);
  1021. if(is_error(obj))
  1022. {
  1023. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1024. }
  1025. else
  1026. {
  1027. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1028. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1029. )
  1030. {
  1031. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1032. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. )
  1034. {
  1035. struct tm tmFrom, tmTo;
  1036. struct timeb tbFrom, tbTo;
  1037. 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) &&
  1038. (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))
  1039. {
  1040. tmFrom.tm_year -= 1900;
  1041. tmFrom.tm_mon -= 1;
  1042. tbFrom.time = mktime(&tmFrom);
  1043. tmTo.tm_year -= 1900;
  1044. tmTo.tm_mon -= 1;
  1045. tbTo.time = mktime(&tmTo);
  1046. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1047. {
  1048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1049. {
  1050. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1053. }
  1054. maxProfile.ChargingProfileId = -1;
  1055. maxProfile.StackLevel = -1;
  1056. if(maxProfile.ChargingProfileId == -1)
  1057. DEBUG_INFO("MaxProfile found.\n");
  1058. else
  1059. DEBUG_INFO("MaxProfile updated.\n");
  1060. // Required item
  1061. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1062. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1063. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1064. if(isUnitA)
  1065. {
  1066. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1067. 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++)
  1068. {
  1069. 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"));
  1070. 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?
  1071. 3:
  1072. 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")));
  1073. 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")));
  1074. }
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1079. 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++)
  1080. {
  1081. 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"));
  1082. 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?
  1083. 3:
  1084. 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")));
  1085. 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));
  1086. }
  1087. }
  1088. // Optional item
  1089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1090. {
  1091. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1092. }
  1093. else
  1094. {
  1095. sprintf((char*)maxProfile.ValidFrom, " ");
  1096. }
  1097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. {
  1099. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1100. }
  1101. else
  1102. {
  1103. sprintf((char*)maxProfile.ValidTo, " ");
  1104. }
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1114. {
  1115. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1116. }
  1117. else
  1118. {
  1119. maxProfile.TransactionId = -1;
  1120. }
  1121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1122. {
  1123. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1124. }
  1125. else
  1126. {
  1127. maxProfile.ChargingSchedule.Duration = 86400;
  1128. }
  1129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1130. {
  1131. 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")));
  1132. }
  1133. else
  1134. {
  1135. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1151. {
  1152. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1155. }
  1156. maxProfile.ChargingProfileId = -1;
  1157. maxProfile.StackLevel = -1;
  1158. if(maxProfile.ChargingProfileId == -1)
  1159. DEBUG_INFO("MaxProfile found.\n");
  1160. else
  1161. DEBUG_INFO("MaxProfile updated.\n");
  1162. // Required item
  1163. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1164. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1165. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1166. if(isUnitA)
  1167. {
  1168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1169. 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++)
  1170. {
  1171. 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"));
  1172. 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?
  1173. 3:
  1174. 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")));
  1175. 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")));
  1176. }
  1177. }
  1178. else
  1179. {
  1180. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1181. 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++)
  1182. {
  1183. 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"));
  1184. 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?
  1185. 3:
  1186. 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")));
  1187. 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));
  1188. }
  1189. }
  1190. // Optional item
  1191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1192. {
  1193. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1194. }
  1195. else
  1196. {
  1197. sprintf((char*)maxProfile.ValidFrom, " ");
  1198. }
  1199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1200. {
  1201. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1202. }
  1203. else
  1204. {
  1205. sprintf((char*)maxProfile.ValidTo, " ");
  1206. }
  1207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1208. {
  1209. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1210. }
  1211. else
  1212. {
  1213. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1214. }
  1215. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1216. {
  1217. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1218. }
  1219. else
  1220. {
  1221. maxProfile.TransactionId = -1;
  1222. }
  1223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1224. {
  1225. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1226. }
  1227. else
  1228. {
  1229. maxProfile.ChargingSchedule.Duration = 86400;
  1230. }
  1231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1232. {
  1233. 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")));
  1234. }
  1235. else
  1236. {
  1237. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1238. }
  1239. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1240. {
  1241. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1242. }
  1243. else
  1244. {
  1245. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. json_object_put(obj);
  1251. }
  1252. fclose(fp);
  1253. /*
  1254. if(maxProfile.ChargingProfileId !=-1)
  1255. {
  1256. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1257. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1258. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1259. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1260. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1261. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1262. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1263. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1264. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1265. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1266. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1270. {
  1271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1274. }
  1275. }
  1276. }
  1277. else
  1278. DEBUG_INFO("MaxProfile not found.\n");
  1279. DEBUG_INFO("------------------------------------\n");*/
  1280. }
  1281. if(maxProfile.ChargingProfileId != -1)
  1282. {
  1283. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1284. {
  1285. if(maxProfile.ChargingSchedule.Duration != -1)
  1286. {
  1287. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1288. 0:
  1289. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1290. }
  1291. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1292. {
  1293. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1294. {
  1295. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1296. 0:
  1297. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1298. if(idxPeriod > 0)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1309. {
  1310. if(maxProfile.ChargingSchedule.Duration != -1)
  1311. {
  1312. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1313. }
  1314. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1315. {
  1316. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1317. {
  1318. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1319. if(idxPeriod > 0)
  1320. {
  1321. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1322. {
  1323. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. else
  1330. {
  1331. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1332. {
  1333. if(maxProfile.ChargingSchedule.Duration != -1)
  1334. {
  1335. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1336. 0:
  1337. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1338. }
  1339. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1340. {
  1341. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1342. {
  1343. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1344. 0:
  1345. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1346. if(idxPeriod > 0)
  1347. {
  1348. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1349. {
  1350. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. else
  1357. {
  1358. if(maxProfile.ChargingSchedule.Duration != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1363. }
  1364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1365. {
  1366. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1367. {
  1368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1369. 0:
  1370. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1371. if(idxPeriod > 0)
  1372. {
  1373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1374. {
  1375. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. /*
  1383. DEBUG_INFO("MaxProfile after align.\n");
  1384. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1385. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1386. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1387. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1388. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1389. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1390. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1391. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1392. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1393. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1394. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1395. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1396. {
  1397. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1398. {
  1399. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1400. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1401. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1402. }
  1403. }
  1404. DEBUG_INFO("------------------------------------\n");*/
  1405. }
  1406. // Find each profile period quantity
  1407. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1408. {
  1409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1410. limitMax = idx+1;
  1411. }
  1412. if(maxProfile.ChargingProfileId != -1)
  1413. {
  1414. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1415. {
  1416. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1417. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1418. (maxProfile.ChargingSchedule.Duration > 0))
  1419. {
  1420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1421. {
  1422. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1423. compositePeriodIdx++;
  1424. }
  1425. else
  1426. {
  1427. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1428. }
  1429. }
  1430. }
  1431. }
  1432. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1433. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1434. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1435. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1436. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1437. {
  1438. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1439. {
  1440. compositeProfile->ChargingProfileId = 1;
  1441. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1442. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1443. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1444. }
  1445. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1446. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1447. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1448. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1449. }
  1450. if(line)
  1451. free(line);
  1452. }
  1453. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1454. {
  1455. FILE *fp;
  1456. char profileFileName[128];
  1457. char *line = NULL;
  1458. size_t len = 0;
  1459. time_t CurrentTime;
  1460. struct tm *tmComposite;
  1461. struct StructChargingProfile maxProfile;
  1462. struct StructChargingProfile defaultTxProfile;
  1463. struct StructChargingProfile txProfile;
  1464. struct StructChargingSchedulePeriod tmpPeriod;
  1465. uint8_t limitMax=0;
  1466. uint8_t limitDef=0;
  1467. uint8_t limitTx=0;
  1468. int compositePeriodIdx = 0;
  1469. CurrentTime = time(NULL);
  1470. tmComposite=localtime(&CurrentTime);
  1471. 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);
  1472. if(isUnitA)
  1473. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1474. else
  1475. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1476. compositeProfile->ChargingSchedule.Duration = durationReq;
  1477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1478. {
  1479. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1482. }
  1483. compositeProfile->ChargingProfileId = 0;
  1484. compositeProfile->StackLevel = 99 ;
  1485. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1486. maxProfile.ChargingProfileId = -1;
  1487. defaultTxProfile.ChargingProfileId = -1;
  1488. txProfile.ChargingProfileId = -1;
  1489. maxProfile.ChargingSchedule.Duration = -1;
  1490. defaultTxProfile.ChargingSchedule.Duration = -1;
  1491. txProfile.ChargingSchedule.Duration = -1;
  1492. system("rm -f /tmp/*.json");
  1493. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1494. /*
  1495. * Search valid charging profile
  1496. */
  1497. //DEBUG_INFO("====================================\n");
  1498. // Search tx profile
  1499. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1500. if((access(profileFileName, F_OK))!=-1)
  1501. {
  1502. fp = fopen(profileFileName, "r");
  1503. while(getline(&line, &len, fp) != -1)
  1504. {
  1505. json_object *obj = NULL;
  1506. obj = json_tokener_parse(line);
  1507. if(is_error(obj))
  1508. {
  1509. DEBUG_ERROR("Parse txProfile from file error.\n");
  1510. }
  1511. else
  1512. {
  1513. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1514. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1515. )
  1516. {
  1517. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1518. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1519. )
  1520. {
  1521. struct tm tmFrom, tmTo;
  1522. struct timeb tbFrom, tbTo;
  1523. 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) &&
  1524. (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))
  1525. {
  1526. tmFrom.tm_year -= 1900;
  1527. tmFrom.tm_mon -= 1;
  1528. tbFrom.time = mktime(&tmFrom);
  1529. tmTo.tm_year -= 1900;
  1530. tmTo.tm_mon -= 1;
  1531. tbTo.time = mktime(&tmTo);
  1532. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1533. {
  1534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1535. {
  1536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1539. }
  1540. txProfile.ChargingProfileId = -1;
  1541. txProfile.StackLevel = -1;
  1542. if(txProfile.ChargingProfileId == -1)
  1543. DEBUG_INFO("TxProfile found.\n");
  1544. else
  1545. DEBUG_INFO("TxProfile updated.\n");
  1546. // Required item
  1547. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1548. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1549. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1550. if(isUnitA)
  1551. {
  1552. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1553. 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++)
  1554. {
  1555. 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"));
  1556. 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?
  1557. 3:
  1558. 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")));
  1559. 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")));
  1560. }
  1561. }
  1562. else
  1563. {
  1564. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1565. 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++)
  1566. {
  1567. 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"));
  1568. 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?
  1569. 3:
  1570. 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")));
  1571. 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));
  1572. }
  1573. }
  1574. // Optional item
  1575. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1576. {
  1577. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)txProfile.ValidFrom, " ");
  1582. }
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.ValidTo, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1592. {
  1593. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)txProfile.RecurrencyKind, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1600. {
  1601. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1602. }
  1603. else
  1604. {
  1605. txProfile.TransactionId = -1;
  1606. }
  1607. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1608. {
  1609. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1610. }
  1611. else
  1612. {
  1613. txProfile.ChargingSchedule.Duration = 86400;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1616. {
  1617. 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")));
  1618. }
  1619. else
  1620. {
  1621. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1624. {
  1625. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1626. }
  1627. else
  1628. {
  1629. txProfile.ChargingSchedule.MinChargingRate = -1;
  1630. }
  1631. }
  1632. }
  1633. }
  1634. else
  1635. {
  1636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1637. {
  1638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1641. }
  1642. txProfile.ChargingProfileId = -1;
  1643. txProfile.StackLevel = -1;
  1644. if(txProfile.ChargingProfileId == -1)
  1645. DEBUG_INFO("TxProfile found.\n");
  1646. else
  1647. DEBUG_INFO("TxProfile updated.\n");
  1648. // Required item
  1649. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1650. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1651. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1652. if(isUnitA)
  1653. {
  1654. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1655. 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++)
  1656. {
  1657. 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"));
  1658. 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?
  1659. 3:
  1660. 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")));
  1661. 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")));
  1662. }
  1663. }
  1664. else
  1665. {
  1666. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1667. 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++)
  1668. {
  1669. 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"));
  1670. 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?
  1671. 3:
  1672. 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")));
  1673. 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));
  1674. }
  1675. }
  1676. // Optional item
  1677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1678. {
  1679. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1680. }
  1681. else
  1682. {
  1683. sprintf((char*)txProfile.ValidFrom, " ");
  1684. }
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1686. {
  1687. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1688. }
  1689. else
  1690. {
  1691. sprintf((char*)txProfile.ValidTo, " ");
  1692. }
  1693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1694. {
  1695. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1696. }
  1697. else
  1698. {
  1699. sprintf((char*)txProfile.RecurrencyKind, " ");
  1700. }
  1701. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1702. {
  1703. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1704. }
  1705. else
  1706. {
  1707. txProfile.TransactionId = -1;
  1708. }
  1709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1710. {
  1711. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1712. }
  1713. else
  1714. {
  1715. txProfile.ChargingSchedule.Duration = 86400;
  1716. }
  1717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1718. {
  1719. 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")));
  1720. }
  1721. else
  1722. {
  1723. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1724. }
  1725. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1726. {
  1727. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1728. }
  1729. else
  1730. {
  1731. txProfile.ChargingSchedule.MinChargingRate = -1;
  1732. }
  1733. }
  1734. }
  1735. }
  1736. json_object_put(obj);
  1737. }
  1738. fclose(fp);
  1739. /*
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1743. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1744. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1745. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1746. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1747. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1748. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1749. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1750. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1751. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1752. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1756. {
  1757. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1758. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1759. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1760. }
  1761. }
  1762. }
  1763. else
  1764. DEBUG_INFO("TxProfile not found.\n");*/
  1765. }
  1766. // Search default tx profile
  1767. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1768. if((access(profileFileName, F_OK))==-1)
  1769. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1770. if((access(profileFileName, F_OK))!=-1)
  1771. {
  1772. fp = fopen(profileFileName, "r");
  1773. while(getline(&line, &len, fp) != -1)
  1774. {
  1775. json_object *obj = NULL;
  1776. obj = json_tokener_parse(line);
  1777. if(is_error(obj))
  1778. {
  1779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1780. }
  1781. else
  1782. {
  1783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1785. )
  1786. {
  1787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1789. )
  1790. {
  1791. struct tm tmFrom, tmTo;
  1792. struct timeb tbFrom, tbTo;
  1793. 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) &&
  1794. (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))
  1795. {
  1796. tmFrom.tm_year -= 1900;
  1797. tmFrom.tm_mon -= 1;
  1798. tbFrom.time = mktime(&tmFrom);
  1799. tmTo.tm_year -= 1900;
  1800. tmTo.tm_mon -= 1;
  1801. tbTo.time = mktime(&tmTo);
  1802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1803. {
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1809. }
  1810. defaultTxProfile.ChargingProfileId = -1;
  1811. defaultTxProfile.StackLevel = -1;
  1812. if(defaultTxProfile.ChargingProfileId == -1)
  1813. DEBUG_INFO("TxDefaultProfile found.\n");
  1814. else
  1815. DEBUG_INFO("TxDefaultProfile updated.\n");
  1816. // Required item
  1817. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1818. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1819. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1820. if(isUnitA)
  1821. {
  1822. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. 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++)
  1824. {
  1825. 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"));
  1826. 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?
  1827. 3:
  1828. 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")));
  1829. 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")));
  1830. }
  1831. }
  1832. else
  1833. {
  1834. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1835. 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++)
  1836. {
  1837. 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"));
  1838. 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?
  1839. 3:
  1840. 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")));
  1841. 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));
  1842. }
  1843. }
  1844. // Optional item
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. {
  1855. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1856. }
  1857. else
  1858. {
  1859. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1860. }
  1861. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1862. {
  1863. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1864. }
  1865. else
  1866. {
  1867. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1868. }
  1869. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1870. {
  1871. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1872. }
  1873. else
  1874. {
  1875. defaultTxProfile.TransactionId = -1;
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1884. }
  1885. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1886. {
  1887. 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")));
  1888. }
  1889. else
  1890. {
  1891. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1892. }
  1893. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1894. {
  1895. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1896. }
  1897. else
  1898. {
  1899. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. else
  1905. {
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1911. }
  1912. defaultTxProfile.ChargingProfileId = -1;
  1913. defaultTxProfile.StackLevel = -1;
  1914. if(defaultTxProfile.ChargingProfileId == -1)
  1915. DEBUG_INFO("TxDefaultProfile found.\n");
  1916. else
  1917. DEBUG_INFO("TxDefaultProfile updated.\n");
  1918. // Required item
  1919. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1920. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1921. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1922. if(isUnitA)
  1923. {
  1924. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1925. 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++)
  1926. {
  1927. 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"));
  1928. 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?
  1929. 3:
  1930. 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")));
  1931. 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")));
  1932. }
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1937. 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++)
  1938. {
  1939. 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"));
  1940. 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?
  1941. 3:
  1942. 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")));
  1943. 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));
  1944. }
  1945. }
  1946. // Optional item
  1947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1948. {
  1949. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1950. }
  1951. else
  1952. {
  1953. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1954. }
  1955. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1956. {
  1957. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1958. }
  1959. else
  1960. {
  1961. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1962. }
  1963. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1964. {
  1965. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1966. }
  1967. else
  1968. {
  1969. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1970. }
  1971. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1972. {
  1973. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1974. }
  1975. else
  1976. {
  1977. defaultTxProfile.TransactionId = -1;
  1978. }
  1979. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1982. }
  1983. else
  1984. {
  1985. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1986. }
  1987. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1988. {
  1989. 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")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1994. }
  1995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1996. {
  1997. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1998. }
  1999. else
  2000. {
  2001. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. json_object_put(obj);
  2007. }
  2008. fclose(fp);
  2009. /*
  2010. if(defaultTxProfile.ChargingProfileId != -1)
  2011. {
  2012. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2013. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2014. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2015. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2016. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2017. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2018. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2019. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2020. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2021. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2022. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2026. {
  2027. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2028. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2029. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2030. }
  2031. }
  2032. }
  2033. else
  2034. DEBUG_INFO("TxDefaultProfile not found.\n");
  2035. DEBUG_INFO("------------------------------------\n");*/
  2036. }
  2037. // Search max profile
  2038. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2039. if((access(profileFileName, F_OK))!=-1)
  2040. {
  2041. fp = fopen(profileFileName, "r");
  2042. while(getline(&line, &len, fp) != -1)
  2043. {
  2044. json_object *obj = NULL;
  2045. obj = json_tokener_parse(line);
  2046. if(is_error(obj))
  2047. {
  2048. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2049. }
  2050. else
  2051. {
  2052. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2053. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2054. )
  2055. {
  2056. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2057. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2058. )
  2059. {
  2060. struct tm tmFrom, tmTo;
  2061. struct timeb tbFrom, tbTo;
  2062. 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) &&
  2063. (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))
  2064. {
  2065. tmFrom.tm_year -= 1900;
  2066. tmFrom.tm_mon -= 1;
  2067. tbFrom.time = mktime(&tmFrom);
  2068. tmTo.tm_year -= 1900;
  2069. tmTo.tm_mon -= 1;
  2070. tbTo.time = mktime(&tmTo);
  2071. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2072. {
  2073. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2074. {
  2075. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2078. }
  2079. maxProfile.ChargingProfileId = -1;
  2080. maxProfile.StackLevel = -1;
  2081. if(maxProfile.ChargingProfileId == -1)
  2082. DEBUG_INFO("MaxProfile found.\n");
  2083. else
  2084. DEBUG_INFO("MaxProfile updated.\n");
  2085. // Required item
  2086. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2087. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2088. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2089. if(isUnitA)
  2090. {
  2091. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2092. 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++)
  2093. {
  2094. 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"));
  2095. 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?
  2096. 3:
  2097. 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")));
  2098. 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")));
  2099. }
  2100. }
  2101. else
  2102. {
  2103. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2104. 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++)
  2105. {
  2106. 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"));
  2107. 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?
  2108. 3:
  2109. 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")));
  2110. 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));
  2111. }
  2112. }
  2113. // Optional item
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2115. {
  2116. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)maxProfile.ValidFrom, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2123. {
  2124. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)maxProfile.ValidTo, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2131. {
  2132. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2133. }
  2134. else
  2135. {
  2136. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2137. }
  2138. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2139. {
  2140. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.TransactionId = -1;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2147. {
  2148. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2149. }
  2150. else
  2151. {
  2152. maxProfile.ChargingSchedule.Duration = 86400;
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2155. {
  2156. 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")));
  2157. }
  2158. else
  2159. {
  2160. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2161. }
  2162. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2163. {
  2164. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2165. }
  2166. else
  2167. {
  2168. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2169. }
  2170. }
  2171. }
  2172. }
  2173. else
  2174. {
  2175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2176. {
  2177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2180. }
  2181. maxProfile.ChargingProfileId = -1;
  2182. maxProfile.StackLevel = -1;
  2183. if(maxProfile.ChargingProfileId == -1)
  2184. DEBUG_INFO("MaxProfile found.\n");
  2185. else
  2186. DEBUG_INFO("MaxProfile updated.\n");
  2187. // Required item
  2188. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2189. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2190. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2191. if(isUnitA)
  2192. {
  2193. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2194. 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++)
  2195. {
  2196. 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"));
  2197. 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?
  2198. 3:
  2199. 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")));
  2200. 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")));
  2201. }
  2202. }
  2203. else
  2204. {
  2205. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2206. 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++)
  2207. {
  2208. 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"));
  2209. 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?
  2210. 3:
  2211. 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")));
  2212. 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));
  2213. }
  2214. }
  2215. // Optional item
  2216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2217. {
  2218. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2219. }
  2220. else
  2221. {
  2222. sprintf((char*)maxProfile.ValidFrom, " ");
  2223. }
  2224. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2225. {
  2226. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2227. }
  2228. else
  2229. {
  2230. sprintf((char*)maxProfile.ValidTo, " ");
  2231. }
  2232. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2233. {
  2234. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2235. }
  2236. else
  2237. {
  2238. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2239. }
  2240. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2241. {
  2242. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2243. }
  2244. else
  2245. {
  2246. maxProfile.TransactionId = -1;
  2247. }
  2248. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2249. {
  2250. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2251. }
  2252. else
  2253. {
  2254. maxProfile.ChargingSchedule.Duration = 86400;
  2255. }
  2256. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2257. {
  2258. 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")));
  2259. }
  2260. else
  2261. {
  2262. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2263. }
  2264. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2265. {
  2266. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2267. }
  2268. else
  2269. {
  2270. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2271. }
  2272. }
  2273. }
  2274. }
  2275. json_object_put(obj);
  2276. }
  2277. fclose(fp);
  2278. /*
  2279. if(maxProfile.ChargingProfileId !=-1)
  2280. {
  2281. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2282. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2283. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2284. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2285. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2286. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2287. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2288. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2289. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2290. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2291. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2293. {
  2294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2295. {
  2296. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2297. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2298. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2299. }
  2300. }
  2301. }
  2302. else
  2303. DEBUG_INFO("MaxProfile not found.\n");
  2304. DEBUG_INFO("------------------------------------\n");*/
  2305. }
  2306. /*
  2307. * Align found profile start schedule & periods
  2308. */
  2309. //DEBUG_INFO("====================================\n");
  2310. /*
  2311. // For local test usage, force modify found profile start schedule info
  2312. 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);
  2313. 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);
  2314. 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);
  2315. */
  2316. if(txProfile.ChargingProfileId != -1)
  2317. {
  2318. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2319. {
  2320. if(txProfile.ChargingSchedule.Duration != -1)
  2321. {
  2322. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2323. 0:
  2324. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2325. }
  2326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2327. {
  2328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2329. {
  2330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2331. 0:
  2332. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2333. if(idxPeriod > 0)
  2334. {
  2335. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2336. {
  2337. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2344. {
  2345. if(txProfile.ChargingSchedule.Duration != -1)
  2346. {
  2347. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2348. 0:
  2349. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2350. }
  2351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2352. {
  2353. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2354. {
  2355. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2356. 0:
  2357. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2358. if(idxPeriod > 0)
  2359. {
  2360. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2361. {
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. }
  2368. else
  2369. {
  2370. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2371. {
  2372. if(txProfile.ChargingSchedule.Duration != -1)
  2373. {
  2374. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2375. 0:
  2376. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2377. }
  2378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2379. {
  2380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2381. {
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2383. 0:
  2384. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2385. if(idxPeriod > 0)
  2386. {
  2387. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2388. {
  2389. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2390. }
  2391. }
  2392. }
  2393. }
  2394. }
  2395. else
  2396. {
  2397. if(txProfile.ChargingSchedule.Duration != -1)
  2398. {
  2399. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2400. 0:
  2401. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2402. }
  2403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2404. {
  2405. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2406. {
  2407. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2408. 0:
  2409. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2410. if(idxPeriod > 0)
  2411. {
  2412. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2413. {
  2414. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. /*
  2422. DEBUG_INFO("txProfile after align.\n");
  2423. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2424. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2425. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2426. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2427. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2428. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2429. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2430. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2431. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2432. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2433. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2435. {
  2436. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2437. {
  2438. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2439. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2440. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2441. }
  2442. }*/
  2443. }
  2444. if(defaultTxProfile.ChargingProfileId != -1)
  2445. {
  2446. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2447. {
  2448. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2449. {
  2450. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2451. 0:
  2452. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2453. }
  2454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2455. {
  2456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2457. {
  2458. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2459. 0:
  2460. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2462. {
  2463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2464. }
  2465. if(idxPeriod > 0)
  2466. {
  2467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2468. {
  2469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2470. }
  2471. }
  2472. }
  2473. }
  2474. }
  2475. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2476. {
  2477. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2478. {
  2479. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2480. 0:
  2481. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2482. }
  2483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2484. {
  2485. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2486. {
  2487. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2488. 0:
  2489. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2491. {
  2492. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2493. }
  2494. if(idxPeriod > 0)
  2495. {
  2496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2497. {
  2498. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. else
  2505. {
  2506. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2507. {
  2508. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2509. {
  2510. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2511. 0:
  2512. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2513. }
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2517. {
  2518. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2519. 0:
  2520. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2521. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2524. }
  2525. if(idxPeriod > 0)
  2526. {
  2527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2528. {
  2529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2530. }
  2531. }
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2538. {
  2539. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2540. 0:
  2541. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2542. }
  2543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2544. {
  2545. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2546. {
  2547. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2548. 0:
  2549. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2551. {
  2552. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. }
  2554. if(idxPeriod > 0)
  2555. {
  2556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2557. {
  2558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. /*
  2566. DEBUG_INFO("defaultTxProfile after align.\n");
  2567. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2568. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2569. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2570. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2571. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2572. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2573. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2574. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2575. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2576. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2577. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2581. {
  2582. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2583. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2584. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2585. }
  2586. }
  2587. DEBUG_INFO("------------------------------------\n");*/
  2588. }
  2589. if(maxProfile.ChargingProfileId != -1)
  2590. {
  2591. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2592. {
  2593. if(maxProfile.ChargingSchedule.Duration != -1)
  2594. {
  2595. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2596. 0:
  2597. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2598. }
  2599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2600. {
  2601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2602. {
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2604. 0:
  2605. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. if(idxPeriod > 0)
  2607. {
  2608. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2609. {
  2610. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2617. {
  2618. if(maxProfile.ChargingSchedule.Duration != -1)
  2619. {
  2620. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2621. 0:
  2622. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2623. }
  2624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2625. {
  2626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2627. {
  2628. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2629. 0:
  2630. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2631. if(idxPeriod > 0)
  2632. {
  2633. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2634. {
  2635. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. else
  2642. {
  2643. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2644. {
  2645. if(maxProfile.ChargingSchedule.Duration != -1)
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2648. 0:
  2649. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2650. }
  2651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2652. {
  2653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2654. {
  2655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2656. 0:
  2657. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2658. if(idxPeriod > 0)
  2659. {
  2660. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2661. {
  2662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. else
  2669. {
  2670. if(maxProfile.ChargingSchedule.Duration != -1)
  2671. {
  2672. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2673. 0:
  2674. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2675. }
  2676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2677. {
  2678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2679. {
  2680. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2681. 0:
  2682. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2683. if(idxPeriod > 0)
  2684. {
  2685. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2686. {
  2687. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. /*
  2695. DEBUG_INFO("MaxProfile after align.\n");
  2696. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2697. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2698. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2699. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2700. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2701. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2702. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2703. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2704. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2705. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2706. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2710. {
  2711. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2712. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2713. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2714. }
  2715. }
  2716. DEBUG_INFO("------------------------------------\n");*/
  2717. }
  2718. /*
  2719. * Merge to conposite schedule
  2720. */
  2721. //DEBUG_INFO("====================================\n");
  2722. // Find each profile period quantity
  2723. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2726. limitMax = idx+1;
  2727. }
  2728. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2729. {
  2730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2731. limitDef = idx+1;
  2732. }
  2733. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2734. {
  2735. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2736. limitTx = idx+1;
  2737. }
  2738. // TxProfile found, composite schedule based on it
  2739. if(txProfile.ChargingProfileId != -1)
  2740. {
  2741. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2742. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2743. {
  2744. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2745. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2746. (txProfile.ChargingSchedule.Duration > 0))
  2747. {
  2748. if(maxProfile.ChargingProfileId != -1)
  2749. {
  2750. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2751. {
  2752. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2753. {
  2754. if((maxProfile.ChargingSchedule.Duration > 0))
  2755. {
  2756. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2757. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2758. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2759. }
  2760. else
  2761. {
  2762. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2763. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2764. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2765. }
  2766. }
  2767. if(idxMaxPeriod == (limitMax-1))
  2768. {
  2769. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2770. {
  2771. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2772. {
  2773. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2774. compositePeriodIdx++;
  2775. }
  2776. else
  2777. {
  2778. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. else
  2785. {
  2786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2787. {
  2788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2789. compositePeriodIdx++;
  2790. }
  2791. else
  2792. {
  2793. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2794. }
  2795. }
  2796. }
  2797. if(idxTxPeriod == (limitTx-1))
  2798. {
  2799. if(defaultTxProfile.ChargingProfileId != -1)
  2800. {
  2801. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2802. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2803. {
  2804. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2806. (defaultTxProfile.ChargingSchedule.Duration>0))
  2807. {
  2808. if(maxProfile.ChargingProfileId != -1)
  2809. {
  2810. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2813. {
  2814. if((maxProfile.ChargingSchedule.Duration > 0))
  2815. {
  2816. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2817. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2818. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2819. }
  2820. else
  2821. {
  2822. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2823. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2824. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2825. }
  2826. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2827. {
  2828. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2829. {
  2830. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2831. compositePeriodIdx++;
  2832. }
  2833. else
  2834. {
  2835. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2836. }
  2837. }
  2838. // Delete duplicate period
  2839. if(compositePeriodIdx > 1)
  2840. {
  2841. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2842. {
  2843. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2845. compositePeriodIdx -= 1;
  2846. }
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2852. {
  2853. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2854. compositePeriodIdx++;
  2855. }
  2856. else
  2857. {
  2858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. }
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2867. {
  2868. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2869. compositePeriodIdx++;
  2870. }
  2871. else
  2872. {
  2873. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2874. }
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2883. else if(defaultTxProfile.ChargingProfileId != -1)
  2884. {
  2885. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2886. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2887. {
  2888. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2889. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2890. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2891. {
  2892. if(maxProfile.ChargingProfileId != -1)
  2893. {
  2894. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2895. {
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2897. {
  2898. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2899. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2900. if((maxProfile.ChargingSchedule.Duration > 0))
  2901. {
  2902. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2903. }
  2904. else
  2905. {
  2906. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2907. }
  2908. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2909. {
  2910. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2911. {
  2912. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2913. compositePeriodIdx++;
  2914. }
  2915. else
  2916. {
  2917. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2918. }
  2919. }
  2920. // Delete duplicate period
  2921. if(compositePeriodIdx > 1)
  2922. {
  2923. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2924. {
  2925. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2927. compositePeriodIdx -= 1;
  2928. }
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2934. {
  2935. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2936. compositePeriodIdx++;
  2937. }
  2938. else
  2939. {
  2940. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2941. }
  2942. break;
  2943. }
  2944. }
  2945. }
  2946. else
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2949. {
  2950. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2951. compositePeriodIdx++;
  2952. }
  2953. else
  2954. {
  2955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. // Fill other period by MaxProfile
  2962. if(maxProfile.ChargingProfileId != -1)
  2963. {
  2964. if(compositePeriodIdx==0)
  2965. {
  2966. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2967. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2968. {
  2969. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2970. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2971. (maxProfile.ChargingSchedule.Duration > 0))
  2972. {
  2973. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2974. {
  2975. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2976. compositePeriodIdx++;
  2977. }
  2978. else
  2979. {
  2980. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else
  2986. {
  2987. int lastCompositePeriodIdx = compositePeriodIdx;
  2988. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2989. {
  2990. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2991. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2992. (maxProfile.ChargingSchedule.Duration > 0))
  2993. {
  2994. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2995. {
  2996. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2997. {
  2998. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  2999. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3000. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3001. }
  3002. else
  3003. {
  3004. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3005. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3006. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3007. }
  3008. }
  3009. if(tmpPeriod.Limit != -1)
  3010. {
  3011. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3012. {
  3013. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3016. compositePeriodIdx++;
  3017. }
  3018. else
  3019. {
  3020. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3021. }
  3022. }
  3023. // Delete duplicate period
  3024. if(compositePeriodIdx > 1)
  3025. {
  3026. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3027. {
  3028. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3030. compositePeriodIdx -= 1;
  3031. }
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. compositeProfile->ChargingSchedule.Duration = durationReq;
  3039. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3040. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3041. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3042. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3043. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3044. {
  3045. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3046. {
  3047. compositeProfile->ChargingProfileId = 1;
  3048. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3049. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3050. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3051. }
  3052. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3053. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3054. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3055. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3056. }
  3057. if(line)
  3058. free(line);
  3059. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3060. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3061. }
  3062. //==========================================
  3063. // Init all share memory
  3064. //==========================================
  3065. int InitShareMemory()
  3066. {
  3067. int result = PASS;
  3068. int MeterSMId;
  3069. //creat ShmSysConfigAndInfo
  3070. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3071. {
  3072. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3073. result = FAIL;
  3074. }
  3075. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3076. {
  3077. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3078. result = FAIL;
  3079. }
  3080. else
  3081. {}
  3082. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3083. {
  3084. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3085. result = FAIL;
  3086. }
  3087. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3088. {
  3089. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3090. result = FAIL;
  3091. }
  3092. else
  3093. {}
  3094. //creat ShmPsuData
  3095. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3096. {
  3097. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3098. result = FAIL;
  3099. }
  3100. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3101. {
  3102. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3103. result = FAIL;
  3104. }
  3105. else
  3106. {}
  3107. //link ShmOCPP16Data
  3108. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3109. {
  3110. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3111. result = FAIL;
  3112. }
  3113. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3114. {
  3115. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3116. result = FAIL;
  3117. }
  3118. else
  3119. {}
  3120. //creat ShmOCPP16DataPH
  3121. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3122. {
  3123. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3124. result = FAIL;
  3125. }
  3126. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3127. {
  3128. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3129. result = FAIL;
  3130. }
  3131. else
  3132. {}
  3133. /****************************** For Initial Settings************************************************/
  3134. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3135. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3136. // allocate Configuration memory address
  3137. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3138. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3140. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3141. //offline MeterValue Interval
  3142. TempMeterValueInterval = 0;
  3143. return result;
  3144. }
  3145. int ProcessShareMemory()
  3146. {
  3147. int result = PASS;
  3148. ParsingRatedCur modelnameInfo={0};
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3162. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3163. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3165. ) // 'D' means DC
  3166. {
  3167. // DO series
  3168. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3169. {
  3170. SystemInitial += 1;
  3171. gunTotalNumber += 1;
  3172. gunType[gun_index] = GUN_TYPE_DO;
  3173. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3174. {
  3175. case Gun_Type_Chademo:
  3176. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3177. break;
  3178. case Gun_Type_CCS_2:
  3179. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3180. break;
  3181. case Gun_Type_GB:
  3182. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3183. break;
  3184. case Gun_Type_AC:
  3185. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3186. break;
  3187. default:
  3188. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3189. break;
  3190. }
  3191. }
  3192. }
  3193. else
  3194. {
  3195. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3196. {
  3197. SystemInitial += 1;
  3198. gunTotalNumber += 1;
  3199. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3200. {
  3201. case Gun_Type_Chademo:
  3202. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3203. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3204. break;
  3205. case Gun_Type_CCS_2:
  3206. gunType[gun_index] = GUN_TYPE_CCS;
  3207. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3208. break;
  3209. case Gun_Type_GB:
  3210. gunType[gun_index] = GUN_TYPE_GBT;
  3211. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3212. break;
  3213. case Gun_Type_AC:
  3214. gunType[gun_index] = GUN_TYPE_AC;
  3215. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3216. break;
  3217. default:
  3218. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3219. break;
  3220. }
  3221. }
  3222. }
  3223. }
  3224. else
  3225. {
  3226. DEBUG_ERROR("Model name parsing fail.\n");
  3227. result = FAIL;
  3228. }
  3229. if(result != PASS)sleep(5);
  3230. return result;
  3231. }
  3232. void CheckSystemValue(void)
  3233. {
  3234. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3235. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3236. char filenmae[100]={0};
  3237. char str[100]={0};
  3238. int tempIndex = 0;
  3239. //===============================
  3240. // send Heartbeat
  3241. //===============================
  3242. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3243. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3244. {
  3245. clientTime.Heartbeat=time((time_t*)NULL);
  3246. if(server_sign == TRUE)
  3247. {
  3248. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3249. }
  3250. else
  3251. {
  3252. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3253. }
  3254. }
  3255. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3256. {
  3257. //parameter for test
  3258. sendHeartbeatRequest(0);
  3259. //==============================================
  3260. // Reset Waiting Time
  3261. //==============================================
  3262. HeartBeatWithNOResponse += 2;
  3263. }
  3264. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3265. {
  3266. //==========================================
  3267. // csu trigger DataTransferReq
  3268. //==========================================
  3269. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3270. {
  3271. sendDataTransferRequest(gun_index);
  3272. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3273. }
  3274. //===============================
  3275. // CSU Trigger Authorize Request
  3276. //===============================
  3277. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3278. {
  3279. sendAuthorizeRequest(0);
  3280. authorizeRetryTimes = authorizeRetryTimes + 1;
  3281. if(authorizeRetryTimes < 3)
  3282. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3283. }
  3284. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3285. {
  3286. authorizeRetryTimes = 0;
  3287. SetOcppConnStatus(FALSE);
  3288. server_sign = FALSE;
  3289. }
  3290. 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))
  3291. {
  3292. sendAuthorizeRequest(0);
  3293. }
  3294. //==============================================
  3295. // Charger start transaction
  3296. //==============================================
  3297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3298. {
  3299. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3300. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3301. sendStartTransactionRequest(gun_index);
  3302. clientTime.StartTransaction = time((time_t*)NULL);
  3303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3304. storeTempStopTransaction(gun_index);
  3305. }
  3306. //==============================================
  3307. // Charger stop transaction
  3308. //==============================================
  3309. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3310. {
  3311. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3312. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3313. sendStopTransactionRequest(gun_index);
  3314. clientTime.StopTransaction = time((time_t*)NULL);
  3315. }
  3316. //==============================================
  3317. // Charger status report
  3318. //==============================================
  3319. //--- Check Mode Change ---//
  3320. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3322. {
  3323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3324. {
  3325. tempIndex = ((gun_index==2) ? 1: 0);
  3326. }
  3327. else
  3328. {
  3329. tempIndex = gun_index;
  3330. }
  3331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3332. {
  3333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3334. {
  3335. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3336. {
  3337. // Sent unplug message for California pricing logic
  3338. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3339. {
  3340. uint8_t ts[20];
  3341. getNowDatetime(ts);
  3342. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3343. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3344. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3345. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3346. }
  3347. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3348. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3349. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3350. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3351. {
  3352. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3353. if((access(filenmae,F_OK))!=-1)
  3354. {
  3355. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3356. sprintf(str,"rm -f %s",filenmae);
  3357. system(str);
  3358. }
  3359. }
  3360. }
  3361. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3362. #if 1 // for TempStopTransaction
  3363. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3364. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3365. {
  3366. checkTempStopTransaction(gun_index);
  3367. }
  3368. #endif
  3369. }
  3370. }
  3371. }
  3372. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3373. {
  3374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3375. {
  3376. tempIndex = ((gun_index==2) ? 1: 0);
  3377. }
  3378. else
  3379. {
  3380. tempIndex = gun_index;
  3381. }
  3382. for (int index = 0; index < CCS_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3385. {
  3386. 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]*/ )
  3387. {
  3388. // Sent unplug message for California pricing logic
  3389. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3390. {
  3391. uint8_t ts[20];
  3392. getNowDatetime(ts);
  3393. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3394. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3395. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3396. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3397. }
  3398. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3399. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3400. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3402. {
  3403. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3404. if((access(filenmae,F_OK))!=-1)
  3405. {
  3406. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3407. sprintf(str,"rm -f %s",filenmae);
  3408. system(str);
  3409. }
  3410. }
  3411. }
  3412. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3413. #if 1 // for TempStopTransaction
  3414. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3415. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3416. {
  3417. checkTempStopTransaction(gun_index);
  3418. }
  3419. #endif
  3420. }
  3421. }
  3422. }
  3423. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3424. {
  3425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3426. {
  3427. tempIndex = ((gun_index==2) ? 1: 0);
  3428. }
  3429. else
  3430. {
  3431. tempIndex = gun_index;
  3432. }
  3433. for (int index = 0; index < GB_QUANTITY; index++)
  3434. {
  3435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3436. {
  3437. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3438. {
  3439. // Sent unplug message for California pricing logic
  3440. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3441. {
  3442. uint8_t ts[20];
  3443. getNowDatetime(ts);
  3444. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3445. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3446. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3447. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3448. }
  3449. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3450. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3451. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3452. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3453. {
  3454. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3455. if((access(filenmae,F_OK))!=-1)
  3456. {
  3457. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3458. sprintf(str,"rm -f %s",filenmae);
  3459. system(str);
  3460. }
  3461. }
  3462. }
  3463. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3464. #if 1 // for TempStopTransaction
  3465. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3466. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3467. {
  3468. checkTempStopTransaction(gun_index);
  3469. }
  3470. #endif
  3471. }
  3472. }
  3473. }
  3474. else if(gunType[gun_index] == GUN_TYPE_DO)
  3475. {
  3476. tempIndex = gun_index;
  3477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3478. {
  3479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3480. {
  3481. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3482. {
  3483. // Sent unplug message for California pricing logic
  3484. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3485. {
  3486. uint8_t ts[20];
  3487. getNowDatetime(ts);
  3488. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3489. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3490. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3491. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3492. }
  3493. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3494. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3495. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3496. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3497. {
  3498. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3499. if((access(filenmae,F_OK))!=-1)
  3500. {
  3501. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3502. sprintf(str,"rm -f %s",filenmae);
  3503. system(str);
  3504. }
  3505. }
  3506. }
  3507. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3508. #if 1 // for TempStopTransaction
  3509. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3510. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3511. {
  3512. checkTempStopTransaction(gun_index);
  3513. }
  3514. #endif
  3515. }
  3516. }
  3517. }
  3518. else
  3519. {
  3520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3521. {
  3522. tempIndex = 2;
  3523. }
  3524. else
  3525. {
  3526. tempIndex = gun_index;
  3527. }
  3528. for (int index = 0; index < AC_QUANTITY; index++)
  3529. {
  3530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3531. {
  3532. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3533. {
  3534. // Sent unplug message for California pricing logic
  3535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3536. {
  3537. uint8_t ts[20];
  3538. getNowDatetime(ts);
  3539. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3540. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3541. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3542. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3543. }
  3544. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3545. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3546. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3547. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3548. {
  3549. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3550. if((access(filenmae,F_OK))!=-1)
  3551. {
  3552. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3553. sprintf(str,"rm -f %s",filenmae);
  3554. system(str);
  3555. }
  3556. }
  3557. }
  3558. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3559. #if 1 // for TempStopTransaction
  3560. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3561. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3562. {
  3563. checkTempStopTransaction(gun_index);
  3564. }
  3565. #endif
  3566. }
  3567. }// END
  3568. }
  3569. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3570. (
  3571. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3572. )
  3573. )
  3574. {
  3575. if(SystemInitial > 0)
  3576. SystemInitial -= 1;
  3577. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3578. sendStatusNotificationRequest(gun_index);
  3579. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3580. }
  3581. //==============================================
  3582. // CSU Trigger Smart Charging Profilw
  3583. //==============================================
  3584. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3585. {
  3586. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3587. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3588. }
  3589. //==============================================
  3590. // Meter report
  3591. //==============================================
  3592. // Trigger MeterValue
  3593. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3594. {
  3595. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3596. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3597. }
  3598. // ClockAlign MeterValue
  3599. 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))
  3600. {
  3601. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3602. {
  3603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3604. {
  3605. tempIndex = ((gun_index==2) ? 1: 0);
  3606. }
  3607. else
  3608. {
  3609. tempIndex = gun_index;
  3610. }
  3611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3612. {
  3613. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3614. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3615. {
  3616. reqClockAlignMeter[gun_index] = 1;
  3617. }
  3618. }// End for CHAdeMO
  3619. }
  3620. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3623. {
  3624. tempIndex = ((gun_index==2) ? 1: 0);
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < CCS_QUANTITY; index++)
  3631. {
  3632. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3633. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3634. {
  3635. reqClockAlignMeter[gun_index] = 1;
  3636. }
  3637. } // End for CCS
  3638. }
  3639. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3640. {
  3641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3642. {
  3643. tempIndex = ((gun_index==2) ? 1: 0);
  3644. }
  3645. else
  3646. {
  3647. tempIndex = gun_index;
  3648. }
  3649. for (int index = 0; index < GB_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. }// End for GB
  3657. }
  3658. else if(gunType[gun_index] == GUN_TYPE_DO)
  3659. {
  3660. tempIndex = gun_index;
  3661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3662. {
  3663. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3664. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3665. {
  3666. reqClockAlignMeter[gun_index] = 1;
  3667. }
  3668. }
  3669. }
  3670. else
  3671. {
  3672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3673. {
  3674. tempIndex = 2;
  3675. }
  3676. else
  3677. {
  3678. tempIndex = gun_index;
  3679. }
  3680. for (int index = 0; index < AC_QUANTITY; index++)
  3681. {
  3682. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3683. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3684. {
  3685. reqClockAlignMeter[gun_index] = 1;
  3686. }
  3687. }//End for AC
  3688. }
  3689. if(reqClockAlignMeter[gun_index] == 1)
  3690. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3691. }
  3692. // Sample period MeterValue
  3693. 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))))
  3694. {
  3695. //check Transaction active
  3696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3697. {
  3698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3699. {
  3700. tempIndex = ((gun_index==2) ? 1: 0);
  3701. }
  3702. else
  3703. {
  3704. tempIndex = gun_index;
  3705. }
  3706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3707. {
  3708. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3709. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3710. {
  3711. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3712. {
  3713. reqSampleMeter[gun_index] = 1;
  3714. }
  3715. }
  3716. }// End for CHAdeMO
  3717. }
  3718. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3721. {
  3722. tempIndex = ((gun_index==2) ? 1: 0);
  3723. }
  3724. else
  3725. {
  3726. tempIndex = gun_index;
  3727. }
  3728. for (int index = 0; index < CCS_QUANTITY; index++)
  3729. {
  3730. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3731. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3732. {
  3733. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3734. {
  3735. reqSampleMeter[gun_index] = 1;
  3736. }
  3737. }
  3738. } // End for CCS
  3739. }
  3740. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3741. {
  3742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3743. {
  3744. tempIndex = ((gun_index==2) ? 1: 0);
  3745. }
  3746. else
  3747. {
  3748. tempIndex = gun_index;
  3749. }
  3750. for (int index = 0; index < GB_QUANTITY; index++)
  3751. {
  3752. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3753. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3756. {
  3757. reqSampleMeter[gun_index] = 1;
  3758. }
  3759. }
  3760. }// End for GB
  3761. }
  3762. else if(gunType[gun_index] == GUN_TYPE_DO)
  3763. {
  3764. tempIndex = gun_index;
  3765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3766. {
  3767. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3768. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3769. {
  3770. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3771. {
  3772. reqSampleMeter[gun_index] = 1;
  3773. }
  3774. }
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3780. {
  3781. tempIndex = 2;
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < AC_QUANTITY; index++)
  3788. {
  3789. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3790. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3791. {
  3792. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3793. {
  3794. reqSampleMeter[gun_index] = 1;
  3795. }
  3796. }
  3797. }//End for AC
  3798. }
  3799. if(reqSampleMeter[gun_index] == 1)
  3800. {
  3801. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3802. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3803. storeTempStopTransaction(gun_index);
  3804. }
  3805. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3806. }
  3807. //==============================================
  3808. // Check Connector reserved
  3809. //==============================================
  3810. //===============================
  3811. // Check if Reserve is expired
  3812. //===============================
  3813. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3814. {
  3815. double diff_t;
  3816. struct tm tp;
  3817. // current time
  3818. time_t t = time(NULL);
  3819. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3820. tp.tm_isdst = -1;
  3821. time_t utc = mktime(&tp);
  3822. diff_t = difftime(utc, t);
  3823. if(diff_t <= 0)
  3824. {
  3825. DEBUG_INFO("reserve expired.\n");
  3826. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3827. }
  3828. }//END OF Check if Reserve is expired
  3829. //==========================================
  3830. // csu trigger FirmwareStatusNotificationReq
  3831. //==========================================
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3833. {
  3834. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3835. }
  3836. //==========================================
  3837. // csu trigger DiagnosticsStatusNotificationReq
  3838. //==========================================
  3839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3840. {
  3841. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3842. }
  3843. //==========================================
  3844. // csu trigger CancelReservationConf
  3845. //==========================================
  3846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3847. {
  3848. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3849. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3850. }
  3851. //==========================================
  3852. // csu trigger ChangeAvailabilityConf
  3853. //==========================================
  3854. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3855. {
  3856. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3857. }
  3858. //==========================================
  3859. // csu trigger UnlockConnectorConf
  3860. //==========================================
  3861. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3862. {
  3863. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3864. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3865. }
  3866. //==========================================
  3867. // csu trigger ReserveNowConf
  3868. //==========================================
  3869. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3870. {
  3871. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3872. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3873. }
  3874. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3875. {
  3876. sendSignCertificateRequest();
  3877. }
  3878. }
  3879. }
  3880. //==========================================
  3881. // send request routine
  3882. //==========================================
  3883. int sendAuthorizeRequest(int gun_index)
  3884. {
  3885. mtrace();
  3886. int result = FAIL;
  3887. char message[100]={0};
  3888. char guid[37];
  3889. char tempdata[65]={0};
  3890. DEBUG_INFO("sendAuthorizeRequest...\n");
  3891. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3892. //Local Authorize
  3893. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3894. {
  3895. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3896. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3897. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3898. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3899. result = PASS;
  3900. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3901. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3902. authorizeRetryTimes = 0;
  3903. return result;
  3904. }
  3905. 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))||
  3906. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3907. {
  3908. // Query from cache
  3909. DEBUG_INFO("Authorize from cache.\n");
  3910. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3911. // Query from list
  3912. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3913. {
  3914. DEBUG_INFO("Authorize from list.\n");
  3915. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3916. }
  3917. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3918. {
  3919. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3920. {
  3921. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3922. }
  3923. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3924. {
  3925. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3926. }
  3927. if(!GetOcppConnStatus())
  3928. {
  3929. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3930. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3931. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3932. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3933. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3934. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3935. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3936. authorizeRetryTimes = 0;
  3937. return result;
  3938. }
  3939. }
  3940. else
  3941. {
  3942. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3943. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3944. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3945. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3946. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3947. else
  3948. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3949. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3950. result = PASS;
  3951. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3952. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3953. authorizeRetryTimes = 0;
  3954. return result;
  3955. }
  3956. }
  3957. //initialize struct Authorize
  3958. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3959. //get data from shared memory
  3960. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3961. random_uuid(guid);
  3962. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3963. LWS_Send(message);
  3964. sprintf(tempdata, "Authorize,%d", gun_index);
  3965. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3966. {
  3967. result = PASS;
  3968. DEBUG_INFO("Authorize mapItem pass\n");
  3969. }
  3970. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3971. return result;
  3972. }
  3973. int sendBootNotificationRequest(void)
  3974. {
  3975. mtrace();
  3976. int result = FAIL;
  3977. char message[500]={0}, payload[700]={0};
  3978. char guid[37]={0};
  3979. char tempdata[65]={0};
  3980. // Fill BootNotification fields
  3981. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3982. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3983. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3984. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3985. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3986. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3987. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3988. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3989. ShmOCPP16DataPH->ChargeBoxId
  3990. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3991. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3992. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3993. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3994. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3995. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3996. random_uuid(guid);
  3997. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3998. LWS_Send(message);
  3999. sprintf(tempdata, "BootNotification,0");
  4000. 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*/)
  4001. {
  4002. result = PASS;
  4003. }
  4004. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4005. strcpy(queuedata,message);
  4006. return result;
  4007. }
  4008. int sendDataTransferRequest(int gun_index)
  4009. {
  4010. mtrace();
  4011. char message[1000]={0};
  4012. char guid[37]={0};
  4013. char tempdata[65]={0};
  4014. int result = FAIL;
  4015. random_uuid(guid);
  4016. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4017. MESSAGE_TYPE_CALL,
  4018. guid,
  4019. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4020. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4021. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4022. LWS_Send(message);
  4023. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4024. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4025. {
  4026. result = PASS;
  4027. DEBUG_INFO("DataTransfer mapItem pass\n");
  4028. }
  4029. return result;
  4030. }
  4031. int sendDiagnosticsStatusNotificationRequest(char *status)
  4032. {
  4033. mtrace();
  4034. int result = FAIL;
  4035. char message[110]={0};
  4036. char guid[37]={0};
  4037. char tempdata[65]={0};
  4038. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4039. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4040. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4041. random_uuid(guid);
  4042. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4043. LWS_SendNow(message);
  4044. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4045. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4046. {
  4047. result = PASS;
  4048. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4049. }
  4050. //#ifdef SystemLogMessage
  4051. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4052. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4053. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4054. //#endif
  4055. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4056. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4057. //record status
  4058. if(strcmp(status,"Idle")==0)
  4059. {
  4060. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4061. }
  4062. else if(strcmp(status,"Uploaded")==0)
  4063. {
  4064. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4065. }
  4066. else if(strcmp(status,"UploadFailed")==0)
  4067. {
  4068. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4069. }
  4070. else if(strcmp(status,"Uploading")==0)
  4071. {
  4072. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4073. }
  4074. return result;
  4075. }
  4076. int sendFirmwareStatusNotificationRequest(char *status)
  4077. {
  4078. mtrace();
  4079. int result = FAIL;
  4080. char message[110]={0};
  4081. char guid[37]={0};
  4082. char tempdata[65]={0};
  4083. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4084. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4085. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4086. random_uuid(guid);
  4087. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4088. LWS_SendNow(message);
  4089. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4090. 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*/)
  4091. {
  4092. result = PASS;
  4093. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4094. }
  4095. //#ifdef SystemLogMessage
  4096. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4097. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4098. //#endif
  4099. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4100. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4101. //record status
  4102. if(strcmp(status,"Downloaded")==0)
  4103. {
  4104. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4105. }
  4106. else if(strcmp(status,"DownloadFailed")==0)
  4107. {
  4108. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4109. }
  4110. else if(strcmp(status,"Downloading")==0)
  4111. {
  4112. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4113. }
  4114. else if(strcmp(status,"Idle")==0)
  4115. {
  4116. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4117. }
  4118. else if(strcmp(status,"InstallationFailed")==0)
  4119. {
  4120. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4121. }
  4122. else if(strcmp(status,"Installing")==0)
  4123. {
  4124. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4125. }
  4126. else if(strcmp(status,"Installed")==0)
  4127. {
  4128. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4129. }
  4130. return result;
  4131. }
  4132. int sendHeartbeatRequest(int gun_index)
  4133. {
  4134. mtrace();
  4135. int result = FAIL;
  4136. char message[80]={0};
  4137. char guid[37]={0};
  4138. char tempdata[65]={0};
  4139. random_uuid(guid);
  4140. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4141. , MESSAGE_TYPE_CALL
  4142. , guid );
  4143. LWS_Send(message);
  4144. sprintf(tempdata, "Heartbeat,%d", 0);
  4145. 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*/)
  4146. {
  4147. result = PASS;
  4148. }
  4149. return result;
  4150. }
  4151. int sendStartTransactionRequest(int gun_index)
  4152. {
  4153. mtrace();
  4154. int result = FAIL;
  4155. char message[250]={0};
  4156. char guid[37]={0};
  4157. struct timeval tmnow;
  4158. struct tm *tm;
  4159. char buf[28];//, usec_buf[6];
  4160. char tempdata[65]={0};
  4161. int tempIndex = 0;
  4162. DEBUG_INFO("sendStartTransactionRequest...\n");
  4163. gettimeofday(&tmnow, NULL);
  4164. time_t t;
  4165. t = time(NULL);
  4166. /*UTC time and date*/
  4167. tm = gmtime(&t);
  4168. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4169. #if 0 // remove temporally
  4170. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4171. strcat(buf,".");
  4172. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4173. strcat(buf,usec_buf);
  4174. #endif
  4175. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4176. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4177. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4178. // clear StartTransaction Response
  4179. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4180. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4181. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4182. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4183. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4184. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4185. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4186. {
  4187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4188. {
  4189. tempIndex = ((gun_index==2) ? 1: 0);
  4190. }
  4191. else
  4192. {
  4193. tempIndex = gun_index;
  4194. }
  4195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4196. {
  4197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4198. {
  4199. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4200. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4201. }
  4202. }
  4203. }
  4204. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4205. {
  4206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4207. {
  4208. tempIndex = ((gun_index==2) ? 1: 0);
  4209. }
  4210. else
  4211. {
  4212. tempIndex = gun_index;
  4213. }
  4214. for (int index = 0; index < CCS_QUANTITY; index++)
  4215. {
  4216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4217. {
  4218. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4219. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4220. }
  4221. }
  4222. }
  4223. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4224. {
  4225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4226. {
  4227. tempIndex = ((gun_index==2) ? 1: 0);
  4228. }
  4229. else
  4230. {
  4231. tempIndex = gun_index;
  4232. }
  4233. for (int index = 0; index < GB_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4236. {
  4237. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4238. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4239. }
  4240. }
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_DO)
  4243. {
  4244. tempIndex = gun_index;
  4245. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4248. {
  4249. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4250. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4251. }
  4252. }
  4253. }
  4254. else
  4255. {
  4256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4257. {
  4258. tempIndex = 2;
  4259. }
  4260. else
  4261. {
  4262. tempIndex = gun_index;
  4263. }
  4264. for (int index = 0; index < AC_QUANTITY; index++)
  4265. {
  4266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4267. {
  4268. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4269. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4270. }
  4271. }
  4272. }
  4273. random_uuid(guid);
  4274. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4275. {
  4276. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4277. , gun_index +1
  4278. , MESSAGE_TYPE_CALL
  4279. , guid
  4280. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4281. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4282. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4283. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4284. }
  4285. else
  4286. {
  4287. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4288. , gun_index +1
  4289. , MESSAGE_TYPE_CALL
  4290. , guid
  4291. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4292. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4293. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4294. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4295. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4296. }
  4297. #if 1
  4298. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4299. 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*/)
  4300. {
  4301. result = PASS;
  4302. }
  4303. #endif
  4304. strcpy(queuedata, message);
  4305. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4306. OCPP_insert_transaction_msg(YES, queuedata);
  4307. return result;
  4308. }
  4309. int sendStatusNotificationRequest(int gun_index)
  4310. {
  4311. mtrace();
  4312. int result = FAIL;
  4313. char message[600]={0};
  4314. char guid[37];
  4315. int currentStatus = 0;
  4316. struct timeval tmnow;
  4317. struct tm *tm;
  4318. char buf[28];//, usec_buf[6];
  4319. char tempdata[65]={0};
  4320. int tempIndex = 0;
  4321. uint8_t isStateChanged = TRUE;
  4322. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4323. gettimeofday(&tmnow, NULL);
  4324. time_t t;
  4325. t = time(NULL);
  4326. /*UTC time and date*/
  4327. tm = gmtime(&t);
  4328. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4329. #if 0 // remove temporally
  4330. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4331. strcat(buf,".");
  4332. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4333. strcat(buf,usec_buf);
  4334. #endif
  4335. //printf("%s",buf);
  4336. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4337. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4338. // it's option
  4339. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4340. /*
  4341. enum _SYSTEM_STATUS
  4342. {
  4343. S_BOOTING = 0,
  4344. S_IDLE, = 1
  4345. S_AUTHORIZING, =2
  4346. S_REASSIGN_CHECK, =3
  4347. S_REASSIGN, =4
  4348. S_PRECHARGE, =5
  4349. S_PREPARING_FOR_EV, =6
  4350. S_PREPARING_FOR_EVSE, =7
  4351. S_CHARGING, =8
  4352. S_TERMINATING, =9
  4353. S_COMPLETE, =10
  4354. S_ALARM, =11
  4355. S_FAULT =12
  4356. }
  4357. */
  4358. //check Transaction active
  4359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4371. {
  4372. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4373. {
  4374. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4375. {
  4376. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4377. {
  4378. currentStatus = Preparing; //OCPP Status: Preparing
  4379. }
  4380. else
  4381. {
  4382. currentStatus = Available; //OCPP Status: Available
  4383. }
  4384. }
  4385. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4386. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4387. ) //S_PRECHARGE
  4388. {
  4389. currentStatus = Preparing; //OCPP Status: Preparing
  4390. }
  4391. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4392. {
  4393. currentStatus = Charging; //OCPP Status: Charging
  4394. }
  4395. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4396. {
  4397. currentStatus = Finishing; //OCPP Status: Finishing
  4398. }
  4399. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4400. {
  4401. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4402. }
  4403. 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
  4404. {
  4405. currentStatus = Unavailable; //OCPP Status: Unavailable
  4406. }
  4407. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4408. {
  4409. currentStatus = Faulted; //OCPP Status: Faulted
  4410. }
  4411. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4412. {
  4413. currentStatus = Reserved; //OCPP Status: Reserved
  4414. }
  4415. } //end of the same index
  4416. }//end of for CHAdeMO_QUANTITY
  4417. }
  4418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CCS_QUANTITY; index++)
  4429. {
  4430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4431. {
  4432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4435. {
  4436. currentStatus = Preparing; //OCPP Status: Preparing
  4437. }
  4438. else
  4439. {
  4440. currentStatus = Available; //OCPP Status: Available
  4441. }
  4442. }
  4443. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4444. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4445. ) //S_PRECHARGE
  4446. {
  4447. currentStatus = Preparing; //OCPP Status: Preparing
  4448. }
  4449. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4450. {
  4451. currentStatus = Charging; //OCPP Status: Charging
  4452. }
  4453. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4454. {
  4455. currentStatus = Finishing; //OCPP Status: Finishing
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4458. {
  4459. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4460. }
  4461. 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
  4462. {
  4463. currentStatus = Unavailable; //OCPP Status : Unavailable
  4464. }
  4465. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4466. {
  4467. currentStatus = Faulted; //OCPP Status: Faulted
  4468. }
  4469. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4470. {
  4471. currentStatus = Reserved; //OCPP Status: Reserved
  4472. }
  4473. } //end of the same index
  4474. } // end of for CCS_QUANTITY
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((gun_index==2) ? 1: 0);
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < GB_QUANTITY; index++)
  4487. {
  4488. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4491. {
  4492. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4493. {
  4494. currentStatus = Preparing; //OCPP Status: Preparing
  4495. }
  4496. else
  4497. {
  4498. currentStatus = Available; //OCPP Status: Available
  4499. }
  4500. }
  4501. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4502. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4503. ) //S_PRECHARGE
  4504. {
  4505. currentStatus = Preparing; //OCPP Status: Preparing
  4506. }
  4507. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4508. {
  4509. currentStatus = Charging; //OCPP Status: Charging
  4510. }
  4511. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4512. {
  4513. currentStatus = Finishing; //OCPP Status: Finishing
  4514. }
  4515. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4516. {
  4517. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4518. }
  4519. 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
  4520. {
  4521. currentStatus = Unavailable; //OCPP Status: Unavailable
  4522. }
  4523. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4524. {
  4525. currentStatus = Faulted; //OCPP Status: Faulted
  4526. }
  4527. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4528. {
  4529. currentStatus = Reserved; //OCPP Status: Reserved
  4530. }
  4531. } //end of the same index
  4532. } // end of for GB_QUANTITY
  4533. }
  4534. else if(gunType[gun_index] == GUN_TYPE_DO)
  4535. {
  4536. tempIndex = gun_index;
  4537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4542. {
  4543. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4544. {
  4545. currentStatus = Preparing; //OCPP Status: Preparing
  4546. }
  4547. else
  4548. {
  4549. currentStatus = Available; //OCPP Status: Available
  4550. }
  4551. }
  4552. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4553. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4554. ) //S_PRECHARGE
  4555. {
  4556. currentStatus = Preparing; //OCPP Status: Preparing
  4557. }
  4558. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4559. {
  4560. currentStatus = Charging; //OCPP Status: Charging
  4561. }
  4562. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4563. {
  4564. currentStatus = Finishing; //OCPP Status: Finishing
  4565. }
  4566. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4567. {
  4568. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4569. }
  4570. 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
  4571. {
  4572. currentStatus = Unavailable; //OCPP Status: Unavailable
  4573. }
  4574. 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
  4575. {
  4576. currentStatus = Faulted; //OCPP Status: Faulted
  4577. }
  4578. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4579. {
  4580. currentStatus = Reserved; //OCPP Status: Reserved
  4581. }
  4582. } //end of the same index
  4583. }
  4584. }
  4585. else
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4588. {
  4589. tempIndex = 2;
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < AC_QUANTITY; index++)
  4596. {
  4597. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4600. {
  4601. 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))
  4602. {
  4603. currentStatus = Preparing; //OCPP Status: Preparing
  4604. }
  4605. else
  4606. {
  4607. currentStatus = Available; //OCPP Status: Available
  4608. }
  4609. }
  4610. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4611. {
  4612. currentStatus = Preparing; //OCPP Status: Preparing
  4613. }
  4614. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4615. {
  4616. currentStatus = Charging; //OCPP Status: Charging
  4617. }
  4618. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4619. {
  4620. currentStatus = Finishing; //OCPP Status: Finishing
  4621. }
  4622. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4623. {
  4624. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4625. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4626. else
  4627. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4628. }
  4629. 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
  4630. {
  4631. currentStatus = Unavailable; //OCPP Status: Unavailable
  4632. }
  4633. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4634. {
  4635. currentStatus = Faulted; //OCPP Status: Faulted
  4636. }
  4637. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4638. {
  4639. currentStatus = Reserved; //OCPP Status: Reserved
  4640. }
  4641. }//end of the same index
  4642. }//end of for AC_QUANTITY
  4643. }
  4644. //it's option
  4645. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4646. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4647. {
  4648. isStateChanged = FALSE;
  4649. }
  4650. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4651. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4652. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4653. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4654. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4655. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4656. random_uuid(guid);
  4657. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4658. , MESSAGE_TYPE_CALL
  4659. , guid
  4660. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4661. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4662. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4663. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4664. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4665. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4666. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4667. if((server_sign == TRUE) && isStateChanged)
  4668. {
  4669. LWS_Send(message);
  4670. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4671. 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*/)
  4672. {
  4673. //DEBUG_ERROR("statusNotification mapitem pass");
  4674. result = PASS;
  4675. }
  4676. }
  4677. else
  4678. {
  4679. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4680. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4681. result = PASS;
  4682. }
  4683. return result;
  4684. }
  4685. int sendStopTransactionRequest(int gun_index)
  4686. {
  4687. mtrace();
  4688. int result = FAIL;
  4689. //char message[1500]={0};
  4690. char guid[37]={0};
  4691. char tempdata[65]={0};
  4692. int tempIndex = 0;
  4693. char TempStopTransaction[256];
  4694. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4695. //int idx_sample=0;
  4696. DEBUG_INFO("sendStopTransactionRequest \n");
  4697. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4698. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4699. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4700. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4701. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4702. {
  4703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4704. {
  4705. tempIndex = ((gun_index==2) ? 1: 0);
  4706. }
  4707. else
  4708. {
  4709. tempIndex = gun_index;
  4710. }
  4711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4712. {
  4713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4714. {
  4715. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4716. }
  4717. }// END OF CHAdeMO_QUANTITY
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < CCS_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4732. {
  4733. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4734. }
  4735. }// END OF CCS_QUANTITY
  4736. }
  4737. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4738. {
  4739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4740. {
  4741. tempIndex = ((gun_index==2) ? 1: 0);
  4742. }
  4743. else
  4744. {
  4745. tempIndex = gun_index;
  4746. }
  4747. for (int index = 0; index < GB_QUANTITY; index++)
  4748. {
  4749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4750. {
  4751. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4752. }
  4753. }// END OF GB_QUANTITY
  4754. }
  4755. else if(gunType[gun_index] == GUN_TYPE_DO)
  4756. {
  4757. tempIndex = gun_index;
  4758. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4759. {
  4760. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4761. {
  4762. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4763. }
  4764. }// END OF GB_QUANTITY
  4765. }
  4766. else
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4769. {
  4770. tempIndex = 2;
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < AC_QUANTITY; index++)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4779. {
  4780. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4781. }
  4782. }// END OF AC_QUANTITY
  4783. }
  4784. //====================================== Stop Transaction Time =====================================================
  4785. struct timeval tmnow;
  4786. struct tm *tm;
  4787. char buf[28];//, usec_buf[6];
  4788. gettimeofday(&tmnow, NULL);
  4789. time_t t;
  4790. t = time(NULL);
  4791. /*UTC time and date*/
  4792. tm = gmtime(&t);
  4793. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4794. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4795. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4796. random_uuid(guid);
  4797. /***********************************transactionData******************************************************/
  4798. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4800. //=================================
  4801. // Transaction_Begin
  4802. //=================================
  4803. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4804. {
  4805. //============================================ Energy.Active.Import.Interval ================================
  4806. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4809. 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*/]);
  4810. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4811. 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))
  4812. {
  4813. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4814. }
  4815. else
  4816. {
  4817. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4818. }
  4819. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4821. }
  4822. //=================================
  4823. // Transaction_End
  4824. //=================================
  4825. // ================================= Current.Import L1 ===============================================
  4826. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4827. {
  4828. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4844. }
  4845. }// End of for CHAdeMO_QUANTITY
  4846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4847. }
  4848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4851. {
  4852. tempIndex = ((gun_index==2) ? 1: 0);
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < CCS_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4861. {
  4862. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4863. }
  4864. }// End of for CCS_QUANTITY
  4865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4866. }
  4867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4868. {
  4869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4870. {
  4871. tempIndex = ((gun_index==2) ? 1: 0);
  4872. }
  4873. else
  4874. {
  4875. tempIndex = gun_index;
  4876. }
  4877. for (int index = 0; index < GB_QUANTITY; index++)
  4878. {
  4879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4880. {
  4881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4882. }
  4883. }// End of for GB_QUANTITY
  4884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4885. }
  4886. else if(gunType[gun_index] == GUN_TYPE_DO)
  4887. {
  4888. tempIndex = gun_index;
  4889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4890. {
  4891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4892. {
  4893. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4894. }
  4895. }
  4896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4897. }
  4898. else
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4901. {
  4902. tempIndex = 2;
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < AC_QUANTITY; index++)
  4909. {
  4910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4911. {
  4912. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4913. }
  4914. }// End of for AC_QUANTITY
  4915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4916. }
  4917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4922. }
  4923. // ================================= Energy.Active.Import.Interval ==============================================
  4924. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4925. {
  4926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4927. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4930. {
  4931. tempIndex = ((gun_index==2) ? 1: 0);
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4942. }
  4943. }// END OF CHAdeMO_QUANTITY
  4944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4945. }
  4946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4949. {
  4950. tempIndex = ((gun_index==2) ? 1: 0);
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < CCS_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4959. {
  4960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4961. }
  4962. }// END OF CCS_QUANTITY
  4963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < GB_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4978. {
  4979. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4980. }
  4981. }// END OF GB_QUANTITY
  4982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4983. }
  4984. else if(gunType[gun_index] == GUN_TYPE_DO)
  4985. {
  4986. tempIndex = gun_index;
  4987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4995. }
  4996. else
  4997. {
  4998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4999. {
  5000. tempIndex = 2;
  5001. }
  5002. else
  5003. {
  5004. tempIndex = gun_index;
  5005. }
  5006. for (int index = 0; index < AC_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5011. }
  5012. }// END OF AC_QUANTITY
  5013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5014. }
  5015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5020. }
  5021. //=================================== Power.Active.Import ==================================================
  5022. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5023. {
  5024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5025. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5036. {
  5037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5038. {
  5039. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5040. }
  5041. } // End for CHAdeMO_QUANTITY
  5042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5043. }
  5044. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5045. {
  5046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5047. {
  5048. tempIndex = ((gun_index==2) ? 1: 0);
  5049. }
  5050. else
  5051. {
  5052. tempIndex = gun_index;
  5053. }
  5054. for (int index = 0; index < CCS_QUANTITY; index++)
  5055. {
  5056. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5057. {
  5058. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5059. }
  5060. } // END for CCS_QUANTITY
  5061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5062. }
  5063. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5064. {
  5065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5066. {
  5067. tempIndex = ((gun_index==2) ? 1: 0);
  5068. }
  5069. else
  5070. {
  5071. tempIndex = gun_index;
  5072. }
  5073. for (int index = 0; index < GB_QUANTITY; index++)
  5074. {
  5075. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5076. {
  5077. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5078. }
  5079. }// END for GB_QUANTITY
  5080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5081. }
  5082. else if(gunType[gun_index] == GUN_TYPE_DO)
  5083. {
  5084. tempIndex = gun_index;
  5085. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5086. {
  5087. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5088. {
  5089. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5090. }
  5091. }
  5092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5093. }
  5094. else
  5095. {
  5096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5097. {
  5098. tempIndex = 2;
  5099. }
  5100. else
  5101. {
  5102. tempIndex = gun_index;
  5103. }
  5104. for (int index = 0; index < AC_QUANTITY; index++)
  5105. {
  5106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5107. {
  5108. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5109. }
  5110. } // END for AC_QUANTITY
  5111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5112. }
  5113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5118. }
  5119. //============================ Voltage L1 ====================================
  5120. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5121. {
  5122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5124. {
  5125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5126. {
  5127. tempIndex = ((gun_index==2) ? 1: 0);
  5128. }
  5129. else
  5130. {
  5131. tempIndex = gun_index;
  5132. }
  5133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5134. {
  5135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5136. {
  5137. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5138. }
  5139. } // END OF FOR CHAdeMO_QUANTITY
  5140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5141. }
  5142. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5143. {
  5144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5145. {
  5146. tempIndex = ((gun_index==2) ? 1: 0);
  5147. }
  5148. else
  5149. {
  5150. tempIndex = gun_index;
  5151. }
  5152. for (int index = 0; index < CCS_QUANTITY; index++)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5155. {
  5156. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5157. }
  5158. } // END OF FOR CCS_QUANTITY
  5159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5160. }
  5161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5162. {
  5163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5164. {
  5165. tempIndex = ((gun_index==2) ? 1: 0);
  5166. }
  5167. else
  5168. {
  5169. tempIndex = gun_index;
  5170. }
  5171. for (int index = 0; index < GB_QUANTITY; index++)
  5172. {
  5173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5174. {
  5175. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5176. }
  5177. } // END OF FOR GB_QUANTITY
  5178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5179. }
  5180. else if(gunType[gun_index] == GUN_TYPE_DO)
  5181. {
  5182. tempIndex = gun_index;
  5183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5184. {
  5185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5186. {
  5187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5188. }
  5189. }
  5190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5191. }
  5192. else
  5193. {
  5194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5195. {
  5196. tempIndex = 2;
  5197. }
  5198. else
  5199. {
  5200. tempIndex = gun_index;
  5201. }
  5202. for (int index = 0; index < AC_QUANTITY; index++)
  5203. {
  5204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5205. {
  5206. 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
  5207. }
  5208. } // END OF FOR AC_QUANTITY
  5209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5210. }
  5211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5216. }
  5217. //====================== End SoC ================================
  5218. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5219. {
  5220. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5221. 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))
  5222. {
  5223. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5224. {
  5225. tempIndex = ((gun_index==2) ? 1: 0);
  5226. }
  5227. else
  5228. {
  5229. tempIndex = gun_index;
  5230. }
  5231. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5232. {
  5233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5234. {
  5235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5236. {
  5237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5238. }
  5239. }
  5240. }
  5241. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5242. {
  5243. for (int index = 0; index < CCS_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5248. }
  5249. }
  5250. }
  5251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5252. {
  5253. for (int index = 0; index < GB_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5258. }
  5259. }
  5260. }
  5261. else if(gunType[gun_index] == GUN_TYPE_DO)
  5262. {
  5263. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5264. {
  5265. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5266. {
  5267. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5268. }
  5269. }
  5270. }
  5271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5277. } // END FOR DC CASE
  5278. }
  5279. // ================================= Current.Import L2 ===============================================
  5280. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5281. {
  5282. // AC 3 phse L2 current
  5283. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5284. {
  5285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5286. {
  5287. tempIndex = 2;
  5288. }
  5289. else
  5290. {
  5291. tempIndex = gun_index;
  5292. }
  5293. for (int index = 0; index < AC_QUANTITY; index++)
  5294. {
  5295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5296. {
  5297. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5298. }
  5299. }// End of for AC_QUANTITY
  5300. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5301. }
  5302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5307. }
  5308. // ================================= Current.Import L3 ===============================================
  5309. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5310. {
  5311. // AC 3 phse L3 current
  5312. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5313. {
  5314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5315. {
  5316. tempIndex = 2;
  5317. }
  5318. else
  5319. {
  5320. tempIndex = gun_index;
  5321. }
  5322. for (int index = 0; index < AC_QUANTITY; index++)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5325. {
  5326. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5327. }
  5328. }// End of for AC_QUANTITY
  5329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5330. }
  5331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5336. }
  5337. //============================ Voltage L2 ====================================
  5338. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5339. {
  5340. // AC 3 phse L2 voltage
  5341. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5342. {
  5343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5344. {
  5345. tempIndex = 2;
  5346. }
  5347. else
  5348. {
  5349. tempIndex = gun_index;
  5350. }
  5351. for (int index = 0; index < AC_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5354. {
  5355. 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
  5356. }
  5357. } // END OF FOR AC_QUANTITY
  5358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5359. }
  5360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5365. }
  5366. //============================ Voltage L3 ====================================
  5367. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5368. {
  5369. // AC 3 phse L3 voltage
  5370. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5371. {
  5372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5373. {
  5374. tempIndex = 2;
  5375. }
  5376. else
  5377. {
  5378. tempIndex = gun_index;
  5379. }
  5380. for (int index = 0; index < AC_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5383. {
  5384. 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
  5385. }
  5386. } // END OF FOR AC_QUANTITY
  5387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5388. }
  5389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5394. }
  5395. //====================== Start SoC ================================
  5396. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5397. {
  5398. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5399. 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))
  5400. {
  5401. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5402. {
  5403. tempIndex = ((gun_index==2) ? 1: 0);
  5404. }
  5405. else
  5406. {
  5407. tempIndex = gun_index;
  5408. }
  5409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5410. {
  5411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5412. {
  5413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5414. {
  5415. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5416. }
  5417. }
  5418. }
  5419. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5420. {
  5421. for (int index = 0; index < CCS_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5426. }
  5427. }
  5428. }
  5429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5430. {
  5431. for (int index = 0; index < GB_QUANTITY; index++)
  5432. {
  5433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5434. {
  5435. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5436. }
  5437. }
  5438. }
  5439. else if(gunType[gun_index] == GUN_TYPE_DO)
  5440. {
  5441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5444. {
  5445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5446. }
  5447. }
  5448. }
  5449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5455. } // END FOR DC CASE
  5456. }
  5457. //================================================ Message create ====================================================
  5458. json_object *StopTransaction = json_object_new_object();
  5459. json_object *transactionDatas = json_object_new_array();
  5460. json_object *sampledValues = json_object_new_array();
  5461. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5462. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5463. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5464. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5465. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5466. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5467. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5468. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5469. {
  5470. json_object *transactionData = json_object_new_object();
  5471. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5472. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5473. {
  5474. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5475. {
  5476. json_object *sampledValue = json_object_new_object();
  5477. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5478. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5479. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5480. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5481. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5482. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5483. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5484. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5485. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5486. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5487. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5488. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5489. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5490. json_object_array_add(sampledValues, sampledValue);
  5491. }
  5492. }
  5493. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5494. json_object_array_add(transactionDatas, transactionData);
  5495. }
  5496. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5497. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5498. ,MESSAGE_TYPE_CALL
  5499. ,guid
  5500. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5501. json_object_put(StopTransaction);
  5502. #if 1 // for TempStopTransaction
  5503. //Delete TempStopTransaction
  5504. if((access(TempStopTransaction,F_OK))!=-1)
  5505. {
  5506. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5507. }
  5508. #endif
  5509. #if 1
  5510. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5511. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5512. {
  5513. result = PASS;
  5514. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5515. }
  5516. #endif
  5517. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5518. OCPP_insert_transaction_msg(NO, queuedata);
  5519. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5520. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5521. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5522. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5523. {
  5524. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5525. }
  5526. //for test
  5527. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5528. return result;
  5529. }
  5530. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5531. {
  5532. mtrace();
  5533. int result = FAIL;
  5534. char guid[37]={0};
  5535. char tempdata[65]={0};
  5536. int tempIndex = 0;
  5537. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5538. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5539. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5540. //set value
  5541. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5542. 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) )?
  5543. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5544. -1);
  5545. random_uuid(guid);
  5546. //UTC Date time
  5547. struct timeval tmnow;
  5548. struct tm *tm;
  5549. char buf[28];//, usec_buf[6];
  5550. gettimeofday(&tmnow, NULL);
  5551. time_t t;
  5552. t = time(NULL);
  5553. /*UTC time and date*/
  5554. tm = gmtime(&t);
  5555. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5557. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5558. //********************************(1)Current.Import L1************************************************/
  5559. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5560. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5561. (dataType == ReadingContext_Trigger))
  5562. {
  5563. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5564. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5565. {
  5566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5567. {
  5568. tempIndex = ((gun_index==2) ? 1: 0);
  5569. }
  5570. else
  5571. {
  5572. tempIndex = gun_index;
  5573. }
  5574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5575. {
  5576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5577. {
  5578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5579. }
  5580. }
  5581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5582. }
  5583. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5584. {
  5585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5586. {
  5587. tempIndex = ((gun_index==2) ? 1: 0);
  5588. }
  5589. else
  5590. {
  5591. tempIndex = gun_index;
  5592. }
  5593. for (int index = 0; index < CCS_QUANTITY; index++)
  5594. {
  5595. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5596. {
  5597. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5598. }
  5599. }
  5600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5601. }
  5602. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5603. {
  5604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5605. {
  5606. tempIndex = ((gun_index==2) ? 1: 0);
  5607. }
  5608. else
  5609. {
  5610. tempIndex = gun_index;
  5611. }
  5612. for (int index = 0; index < GB_QUANTITY; index++)
  5613. {
  5614. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5615. {
  5616. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5617. }
  5618. }
  5619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5620. }
  5621. else if(gunType[gun_index] == GUN_TYPE_DO)
  5622. {
  5623. tempIndex = gun_index;
  5624. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5625. {
  5626. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5627. {
  5628. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5629. }
  5630. }
  5631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5632. }
  5633. else
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5636. {
  5637. tempIndex = 2;
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < AC_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5648. }
  5649. }
  5650. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5651. }
  5652. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5653. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5654. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5655. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5656. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5657. }
  5658. //********************************(2)Energy.Active.Import.Register ************************************************/
  5659. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5660. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5661. (dataType == ReadingContext_Trigger))
  5662. {
  5663. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5664. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5667. {
  5668. tempIndex = ((gun_index==2) ? 1: 0);
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5679. }
  5680. }
  5681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5682. }
  5683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5684. {
  5685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5686. {
  5687. tempIndex = ((gun_index==2) ? 1: 0);
  5688. }
  5689. else
  5690. {
  5691. tempIndex = gun_index;
  5692. }
  5693. for (int index = 0; index < CCS_QUANTITY; index++)
  5694. {
  5695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5696. {
  5697. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5698. }
  5699. }
  5700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5701. }
  5702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5703. {
  5704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5705. {
  5706. tempIndex = ((gun_index==2) ? 1: 0);
  5707. }
  5708. else
  5709. {
  5710. tempIndex = gun_index;
  5711. }
  5712. for (int index = 0; index < GB_QUANTITY; index++)
  5713. {
  5714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5715. {
  5716. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5717. }
  5718. }
  5719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5720. }
  5721. else if(gunType[gun_index] == GUN_TYPE_DO)
  5722. {
  5723. tempIndex = gun_index;
  5724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5725. {
  5726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5727. {
  5728. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5729. }
  5730. }
  5731. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5732. }
  5733. else
  5734. {
  5735. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5736. {
  5737. tempIndex = 2;
  5738. }
  5739. else
  5740. {
  5741. tempIndex = gun_index;
  5742. }
  5743. for (int index = 0; index < AC_QUANTITY; index++)
  5744. {
  5745. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5746. {
  5747. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5748. }
  5749. }
  5750. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5751. }
  5752. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5753. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5754. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5755. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5756. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5757. }
  5758. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5759. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5760. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5761. (dataType == ReadingContext_Trigger))
  5762. {
  5763. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5764. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5765. {
  5766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5767. {
  5768. tempIndex = ((gun_index==2) ? 1: 0);
  5769. }
  5770. else
  5771. {
  5772. tempIndex = gun_index;
  5773. }
  5774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5777. {
  5778. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5779. }
  5780. } // END OF FOR CHAdeMO_QUANTITY
  5781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5782. }
  5783. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5784. {
  5785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5786. {
  5787. tempIndex = ((gun_index==2) ? 1: 0);
  5788. }
  5789. else
  5790. {
  5791. tempIndex = gun_index;
  5792. }
  5793. for (int index = 0; index < CCS_QUANTITY; index++)
  5794. {
  5795. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5796. {
  5797. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5798. }
  5799. } // END OF CCS_QUANTITY
  5800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5801. }
  5802. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5803. {
  5804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5805. {
  5806. tempIndex = ((gun_index==2) ? 1: 0);
  5807. }
  5808. else
  5809. {
  5810. tempIndex = gun_index;
  5811. }
  5812. for (int index = 0; index < GB_QUANTITY; index++)
  5813. {
  5814. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5815. {
  5816. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5817. }
  5818. } // END OF GB_QUANTITY
  5819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5820. }
  5821. else if(gunType[gun_index] == GUN_TYPE_DO)
  5822. {
  5823. tempIndex = gun_index;
  5824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5829. }
  5830. }
  5831. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5832. }
  5833. else
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5836. {
  5837. tempIndex = 2;
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < AC_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5848. }
  5849. }
  5850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5851. }
  5852. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5853. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5854. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5855. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5856. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5857. }
  5858. //********************************(4)Power.Active.Import************************************************/
  5859. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5860. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5861. (dataType == ReadingContext_Trigger))
  5862. {
  5863. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5867. {
  5868. tempIndex = ((gun_index==2) ? 1: 0);
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5879. }
  5880. } // END OF FOR
  5881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5882. }
  5883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5884. {
  5885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5886. {
  5887. tempIndex = ((gun_index==2) ? 1: 0);
  5888. }
  5889. else
  5890. {
  5891. tempIndex = gun_index;
  5892. }
  5893. for (int index = 0; index < CCS_QUANTITY; index++)
  5894. {
  5895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5896. {
  5897. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5898. }
  5899. }
  5900. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5901. }
  5902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5903. {
  5904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5905. {
  5906. tempIndex = ((gun_index==2) ? 1: 0);
  5907. }
  5908. else
  5909. {
  5910. tempIndex = gun_index;
  5911. }
  5912. for (int index = 0; index < GB_QUANTITY; index++)
  5913. {
  5914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5915. {
  5916. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5917. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5918. }
  5919. }
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5921. }
  5922. else if(gunType[gun_index] == GUN_TYPE_DO)
  5923. {
  5924. tempIndex = gun_index;
  5925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5928. {
  5929. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5930. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5931. }
  5932. }
  5933. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5934. }
  5935. else
  5936. {
  5937. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5938. {
  5939. tempIndex = 2;
  5940. }
  5941. else
  5942. {
  5943. tempIndex = gun_index;
  5944. }
  5945. for (int index = 0; index < AC_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5948. {
  5949. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5950. }
  5951. }
  5952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5953. }
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5956. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5957. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5958. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5959. }
  5960. //***********************************************(5)VOLTAGE L1******************************************************/
  5961. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5962. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5963. (dataType == ReadingContext_Trigger))
  5964. {
  5965. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5966. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5967. {
  5968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5969. {
  5970. tempIndex = ((gun_index==2) ? 1: 0);
  5971. }
  5972. else
  5973. {
  5974. tempIndex = gun_index;
  5975. }
  5976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5981. }
  5982. }
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5984. }
  5985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5986. {
  5987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5988. {
  5989. tempIndex = ((gun_index==2) ? 1: 0);
  5990. }
  5991. else
  5992. {
  5993. tempIndex = gun_index;
  5994. }
  5995. for (int index = 0; index < CCS_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5998. {
  5999. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6000. }
  6001. }
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6003. }
  6004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6005. {
  6006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6007. {
  6008. tempIndex = ((gun_index==2) ? 1: 0);
  6009. }
  6010. else
  6011. {
  6012. tempIndex = gun_index;
  6013. }
  6014. for (int index = 0; index < GB_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6019. }
  6020. }
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6022. }
  6023. else if(gunType[gun_index] == GUN_TYPE_DO)
  6024. {
  6025. tempIndex = gun_index;
  6026. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6031. }
  6032. }
  6033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6034. }
  6035. else
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6038. {
  6039. tempIndex = 2;
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < AC_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6050. }
  6051. }
  6052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6053. }
  6054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6059. }
  6060. //***********************************************(6)SOC******************************************************/
  6061. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6062. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6063. (dataType == ReadingContext_Trigger))
  6064. {
  6065. 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))
  6066. {
  6067. //idx_sample=5;
  6068. //sampledValue = NULL;
  6069. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6078. {
  6079. //tempIndex = ((gun_index==2) ? 1: 0);
  6080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6085. }
  6086. }
  6087. }
  6088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6089. {
  6090. //tempIndex = ((gun_index==2) ? 1: 0);
  6091. for (int index = 0; index < CCS_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6094. {
  6095. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6096. }
  6097. }
  6098. }
  6099. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6100. {
  6101. //tempIndex = ((gun_index==2) ? 1: 0);
  6102. for (int index = 0; index < GB_QUANTITY; index++)
  6103. {
  6104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6105. {
  6106. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6107. }
  6108. }
  6109. }
  6110. else if(gunType[gun_index] == GUN_TYPE_DO)
  6111. {
  6112. //tempIndex = ((gun_index==2) ? 1: 0);
  6113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6114. {
  6115. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6116. {
  6117. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6118. }
  6119. }
  6120. }
  6121. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6122. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6123. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6124. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6126. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6127. }
  6128. }
  6129. //********************************(7)Current.Import L2************************************************/
  6130. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6131. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6132. (dataType == ReadingContext_Trigger))
  6133. {
  6134. // Only for AC 3 phase
  6135. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6136. {
  6137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6138. {
  6139. tempIndex = 2;
  6140. }
  6141. else
  6142. {
  6143. tempIndex = gun_index;
  6144. }
  6145. for (int index = 0; index < AC_QUANTITY; index++)
  6146. {
  6147. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6148. {
  6149. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6150. }
  6151. }
  6152. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6153. }
  6154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6156. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6157. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6158. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6159. }
  6160. //********************************(8)Current.Import L3************************************************/
  6161. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6162. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6163. (dataType == ReadingContext_Trigger))
  6164. {
  6165. // Only for AC 3 phase
  6166. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6181. }
  6182. }
  6183. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6188. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6190. }
  6191. //***********************************************(9)VOLTAGE L2******************************************************/
  6192. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6193. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6194. (dataType == ReadingContext_Trigger))
  6195. {
  6196. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6197. {
  6198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6199. {
  6200. tempIndex = 2;
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. for (int index = 0; index < AC_QUANTITY; index++)
  6207. {
  6208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6209. {
  6210. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6211. }
  6212. }
  6213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6214. }
  6215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6217. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6220. }
  6221. //***********************************************(10)VOLTAGE L3******************************************************/
  6222. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6223. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6224. (dataType == ReadingContext_Trigger))
  6225. {
  6226. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6227. {
  6228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6229. {
  6230. tempIndex = 2;
  6231. }
  6232. else
  6233. {
  6234. tempIndex = gun_index;
  6235. }
  6236. for (int index = 0; index < AC_QUANTITY; index++)
  6237. {
  6238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6239. {
  6240. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6241. }
  6242. }
  6243. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6244. }
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6250. }
  6251. //***********************************************(11)Current.Offered******************************************************/
  6252. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6253. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6254. (dataType == ReadingContext_Trigger))
  6255. {
  6256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6258. {
  6259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6260. {
  6261. tempIndex = ((gun_index==2) ? 1: 0);
  6262. }
  6263. else
  6264. {
  6265. tempIndex = gun_index;
  6266. }
  6267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6270. {
  6271. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6272. }
  6273. } // END OF FOR CHAdeMO_QUANTITY
  6274. }
  6275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6276. {
  6277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6278. {
  6279. tempIndex = ((gun_index==2) ? 1: 0);
  6280. }
  6281. else
  6282. {
  6283. tempIndex = gun_index;
  6284. }
  6285. for (int index = 0; index < CCS_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6288. {
  6289. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6290. }
  6291. } // END OF CCS_QUANTITY
  6292. }
  6293. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6294. {
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6296. {
  6297. tempIndex = ((gun_index==2) ? 1: 0);
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. for (int index = 0; index < GB_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6308. }
  6309. } // END OF GB_QUANTITY
  6310. }
  6311. else if(gunType[gun_index] == GUN_TYPE_DO)
  6312. {
  6313. tempIndex = gun_index;
  6314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6317. {
  6318. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6319. }
  6320. }
  6321. }
  6322. else
  6323. {
  6324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6325. {
  6326. tempIndex = 2;
  6327. }
  6328. else
  6329. {
  6330. tempIndex = gun_index;
  6331. }
  6332. for (int index = 0; index < AC_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6335. {
  6336. uint16_t currentOffer;
  6337. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6338. {
  6339. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6340. }
  6341. else
  6342. {
  6343. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6344. }
  6345. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6346. }
  6347. }
  6348. }
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6353. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6354. }
  6355. //***********************************************(12)Power.Offered******************************************************/
  6356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6358. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6359. {
  6360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6361. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6362. {
  6363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6364. {
  6365. tempIndex = ((gun_index==2) ? 1: 0);
  6366. }
  6367. else
  6368. {
  6369. tempIndex = gun_index;
  6370. }
  6371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6372. {
  6373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6374. {
  6375. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6376. }
  6377. } // END OF FOR CHAdeMO_QUANTITY
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < CCS_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6394. }
  6395. } // END OF CCS_QUANTITY
  6396. }
  6397. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6400. {
  6401. tempIndex = ((gun_index==2) ? 1: 0);
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < GB_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6410. {
  6411. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6412. }
  6413. } // END OF GB_QUANTITY
  6414. }
  6415. else if(gunType[gun_index] == GUN_TYPE_DO)
  6416. {
  6417. tempIndex = gun_index;
  6418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6419. {
  6420. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6421. {
  6422. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6423. }
  6424. }
  6425. }
  6426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6428. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6431. }
  6432. // Message create ====================================================================================================
  6433. if(TRUE)
  6434. {
  6435. json_object *MeterValueReq = json_object_new_object();
  6436. json_object *MeterValues = json_object_new_array();
  6437. json_object *sampledValues = json_object_new_array();
  6438. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6439. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6440. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6441. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6442. {
  6443. json_object *MeterValue = json_object_new_object();
  6444. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6445. {
  6446. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6447. {
  6448. json_object *sampledValue = json_object_new_object();
  6449. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6450. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6451. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6452. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6453. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6454. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6455. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6456. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6457. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6458. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6459. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6460. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6461. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6462. json_object_array_add(sampledValues, sampledValue);
  6463. }
  6464. }
  6465. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6466. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6467. json_object_array_add(MeterValues, MeterValue);
  6468. }
  6469. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6470. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6471. ,gun_index + 1
  6472. ,MESSAGE_TYPE_CALL
  6473. ,guid
  6474. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6475. json_object_put(MeterValueReq);
  6476. }
  6477. // Put request guid to hash map
  6478. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6479. 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*/)
  6480. {
  6481. result = PASS;
  6482. //DEBUG_INFO("MeterValues mapitem pass\n");
  6483. }
  6484. if((dataType != ReadingContext_Trigger) &&
  6485. (dataType != ReadingContext_Sample_Clock) &&
  6486. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6487. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6488. else
  6489. {
  6490. if(FirstHeartBeat)
  6491. LWS_Send(queuedata +2);
  6492. }
  6493. return result;
  6494. }
  6495. int sendLogStatusNotificationRequest(char *status)
  6496. {
  6497. mtrace();
  6498. int result = PASS;
  6499. char message[4096]={0};
  6500. char guid[37]={0};
  6501. char tempdata[128]={0};
  6502. json_object *LogStatusNotification = json_object_new_object();
  6503. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6504. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6505. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6506. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6507. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6508. random_uuid(guid);
  6509. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6510. json_object_put(LogStatusNotification);
  6511. LWS_Send(message);
  6512. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6513. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6514. {
  6515. result = PASS;
  6516. }
  6517. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6518. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6519. return result;
  6520. }
  6521. int sendSecurityEventNotificationRequest()
  6522. {
  6523. mtrace();
  6524. int result = PASS;
  6525. char message[4096]={0};
  6526. char guid[37]={0};
  6527. char tempdata[128]={0};
  6528. json_object *SecurityEventNotification = json_object_new_object();
  6529. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6530. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6531. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6532. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6533. random_uuid(guid);
  6534. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6535. json_object_put(SecurityEventNotification);
  6536. LWS_Send(message);
  6537. sprintf(tempdata, "SecurityEventNotification,0");
  6538. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6539. {
  6540. result = PASS;
  6541. }
  6542. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6543. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6544. return result;
  6545. }
  6546. int sendSignCertificateRequest()
  6547. {
  6548. mtrace();
  6549. int result = PASS;
  6550. char message[4096]={0};
  6551. char guid[37]={0};
  6552. char tempdata[128]={0};
  6553. json_object *SignCertificate = json_object_new_object();
  6554. DEBUG_INFO("sendSignCertificateRequest...\n");
  6555. // Read csr file content
  6556. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6557. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6558. char *line = NULL;
  6559. size_t len = 0;
  6560. while(getline(&line, &len, fp) != -1)
  6561. {
  6562. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6563. {
  6564. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6565. }
  6566. }
  6567. fclose(fp);
  6568. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6569. random_uuid(guid);
  6570. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6571. json_object_put(SignCertificate);
  6572. LWS_Send(message);
  6573. sprintf(tempdata, "SignCertificate,0");
  6574. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6575. {
  6576. result = PASS;
  6577. }
  6578. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6579. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6580. return result;
  6581. }
  6582. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6583. {
  6584. mtrace();
  6585. int result = PASS;
  6586. char message[110]={0};
  6587. char guid[37]={0};
  6588. char tempdata[65]={0};
  6589. json_object *FirmwareStatusNotification = json_object_new_object();
  6590. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6591. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6592. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6593. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6594. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6595. random_uuid(guid);
  6596. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6597. json_object_put(FirmwareStatusNotification);
  6598. LWS_Send(message);
  6599. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6600. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6601. {
  6602. result = PASS;
  6603. }
  6604. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6605. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6606. return result;
  6607. }
  6608. //==========================================
  6609. // send confirm routine
  6610. //==========================================
  6611. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6612. {
  6613. mtrace();
  6614. int result = FAIL;
  6615. char message[100]={0};
  6616. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6617. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6618. LWS_Send(message);
  6619. result = TRUE;
  6620. return result;
  6621. }
  6622. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6623. {
  6624. mtrace();
  6625. int result = FAIL;
  6626. char message[100]={0};
  6627. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6628. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6629. LWS_Send(message);
  6630. result = TRUE;
  6631. return result;
  6632. }
  6633. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6634. {
  6635. mtrace();
  6636. int result = FAIL;
  6637. char message[100]={0};
  6638. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6639. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6640. LWS_Send(message);
  6641. result = TRUE;
  6642. return result;
  6643. }
  6644. int sendClearCacheConfirmation(char *uuid,char *payload)
  6645. {
  6646. mtrace();
  6647. int result = FAIL;
  6648. char message[500]={0};
  6649. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6650. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6651. LWS_Send(message);
  6652. return result;
  6653. }
  6654. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6655. {
  6656. mtrace();
  6657. int result = FAIL;
  6658. char message[500]={0};
  6659. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6660. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6661. LWS_Send(message);
  6662. return result;
  6663. }
  6664. int sendDataTransferConfirmation(char *uuid,char *payload)
  6665. {
  6666. mtrace();
  6667. char statusStr[20]={0};
  6668. char dataStr[10]={0};
  6669. char sstr[20]={0};
  6670. int c = 0;
  6671. char *loc;
  6672. int result = FAIL;
  6673. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6674. /**********************status**************************/
  6675. loc = strstr(payload, "status");
  6676. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6677. c = 0;
  6678. while (loc[3+strlen("status")+c] != '\"')
  6679. {
  6680. sstr[c] = loc[3+strlen("status")+c];
  6681. c++;
  6682. }
  6683. sstr[c] = '\0';
  6684. strcpy(statusStr, sstr);
  6685. /**********************data**************************/
  6686. loc = strstr(payload, "data");
  6687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6688. c = 0;
  6689. while (loc[3+strlen("data")+c] != '\"')
  6690. {
  6691. sstr[c] = loc[3+strlen("data")+c];
  6692. c++;
  6693. }
  6694. sstr[c] = '\0';
  6695. strcpy(dataStr, sstr);
  6696. return result;
  6697. }
  6698. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6699. {
  6700. mtrace();
  6701. int result = FAIL;
  6702. char message[1000]={0};
  6703. int CompositeScheduleIndex = 0;
  6704. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6705. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6706. if(nPeriod == 0)
  6707. {
  6708. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6709. {
  6710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6711. ,MESSAGE_TYPE_CALLRESULT
  6712. ,uuid
  6713. ,payload
  6714. ,connectorIdInt);
  6715. }
  6716. else
  6717. {
  6718. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6719. ,MESSAGE_TYPE_CALLRESULT
  6720. ,uuid
  6721. ,payload
  6722. ,connectorIdInt
  6723. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6724. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6725. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6726. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6727. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6728. }
  6729. }
  6730. else
  6731. {
  6732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6733. ,MESSAGE_TYPE_CALLRESULT
  6734. ,uuid
  6735. ,payload
  6736. ,connectorIdInt
  6737. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6738. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6739. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6740. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6741. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6742. {
  6743. if (idx_sample == 0)
  6744. {
  6745. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6746. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6747. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6748. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6749. }
  6750. else
  6751. {
  6752. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6753. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6754. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6755. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6756. }
  6757. }
  6758. sprintf(message + strlen(message), "]}}]");
  6759. }
  6760. LWS_Send(message);
  6761. result = TRUE;
  6762. return result;
  6763. }
  6764. int sendGetConfigurationConfirmation(char *uuid)
  6765. {
  6766. mtrace();
  6767. int result = FAIL;
  6768. int MaxKeySupported = 0;
  6769. int sentConfigurationNumber= 0;
  6770. int sentunConfigurationNumber= 0;
  6771. char message[1024*10]={0};
  6772. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6773. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6774. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6775. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6776. ,MESSAGE_TYPE_CALLRESULT
  6777. ,uuid );
  6778. //configuration key
  6779. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6780. {
  6781. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6782. {
  6783. if (sentConfigurationNumber == 0)
  6784. {
  6785. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6786. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6787. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6788. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6789. }
  6790. else
  6791. {
  6792. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6793. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6794. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6795. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6796. }
  6797. sentConfigurationNumber = sentConfigurationNumber + 1;
  6798. }
  6799. }
  6800. sprintf(message + strlen(message), "]");
  6801. if(UnknownKeynum != 0)
  6802. {
  6803. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6804. //unkown key
  6805. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6806. {
  6807. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6808. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6809. if(sentunConfigurationNumber == 0)
  6810. {
  6811. sprintf(message + strlen(message), "\"%s\""
  6812. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6813. }
  6814. else
  6815. {
  6816. sprintf(message + strlen(message), ",\"%s\""
  6817. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6818. }
  6819. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6820. }
  6821. sprintf(message + strlen(message), "]");
  6822. }
  6823. sprintf(message + strlen(message), "}]");
  6824. LWS_Send(message);
  6825. return result;
  6826. }
  6827. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6828. {
  6829. mtrace();
  6830. int result = FAIL;
  6831. char message[400]={0};
  6832. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6833. if(strcmp(payload,"")==0)
  6834. {
  6835. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6836. }
  6837. else
  6838. {
  6839. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6840. }
  6841. LWS_Send(message);
  6842. result = TRUE;
  6843. return result;
  6844. }
  6845. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6846. {
  6847. mtrace();
  6848. int result = FAIL;
  6849. char message[80]={0};
  6850. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6851. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6852. LWS_Send(message);
  6853. result = TRUE;
  6854. return result;
  6855. }
  6856. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6857. {
  6858. mtrace();
  6859. int result = FAIL;
  6860. char message[80]={0};
  6861. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6863. LWS_Send(message);
  6864. result = TRUE;
  6865. return result;
  6866. }
  6867. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6868. {
  6869. mtrace();
  6870. int result = FAIL;
  6871. char message[80]={0};
  6872. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6874. LWS_Send(message);
  6875. result = TRUE;
  6876. return result;
  6877. }
  6878. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6879. {
  6880. mtrace();
  6881. int result = FAIL;
  6882. char message[80]={0};
  6883. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6884. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6886. LWS_Send(message);
  6887. result = TRUE;
  6888. return result;
  6889. }
  6890. int sendResetConfirmation(char *uuid,char *payload)
  6891. {
  6892. mtrace();
  6893. int result = FAIL;
  6894. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6895. char message[80]={0};
  6896. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6897. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6898. LWS_Send(message);
  6899. result = TRUE;
  6900. return result;
  6901. }
  6902. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6903. {
  6904. mtrace();
  6905. int result = FAIL;
  6906. char message[500]={0};
  6907. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6908. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6909. LWS_Send(message);
  6910. result = TRUE;
  6911. return result;
  6912. }
  6913. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6914. {
  6915. mtrace();
  6916. int result = FAIL;
  6917. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6918. char message[80]={0};
  6919. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6920. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6921. LWS_Send(message);
  6922. result = TRUE;
  6923. return result;
  6924. }
  6925. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6926. {
  6927. mtrace();
  6928. int result = FAIL;
  6929. char message[80]={0};
  6930. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6931. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6932. LWS_Send(message);
  6933. result = TRUE;
  6934. return result;
  6935. }
  6936. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6937. {
  6938. mtrace();
  6939. int result = FAIL;
  6940. char message[80]={0};
  6941. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6942. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6944. LWS_Send(message);
  6945. result = TRUE;
  6946. return result;
  6947. }
  6948. int sendUpdateFirmwareConfirmation(char *uuid)
  6949. {
  6950. mtrace();
  6951. int result = FAIL;
  6952. char message[60]={0};
  6953. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6954. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6955. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6956. LWS_Send(message);
  6957. result = TRUE;
  6958. return result;
  6959. }
  6960. int sendCertificateSignedConfirmation(char *uuid)
  6961. {
  6962. mtrace();
  6963. int result = PASS;
  6964. char message[4096]={0};
  6965. json_object *CertificateSigned = json_object_new_object();
  6966. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6967. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6968. sprintf(message,"[%d,\"%s\",%s]"
  6969. ,MESSAGE_TYPE_CALLRESULT
  6970. ,uuid
  6971. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6972. json_object_put(CertificateSigned);
  6973. LWS_Send(message);
  6974. return result;
  6975. }
  6976. int sendDeleteCertificateConfirmation(char *uuid)
  6977. {
  6978. mtrace();
  6979. int result = PASS;
  6980. char message[4096]={0};
  6981. json_object *DeleteCertificate = json_object_new_object();
  6982. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6983. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6984. sprintf(message,"[%d,\"%s\",%s]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6988. json_object_put(DeleteCertificate);
  6989. LWS_Send(message);
  6990. return result;
  6991. }
  6992. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6993. {
  6994. mtrace();
  6995. int result = PASS;
  6996. char message[4096]={0};
  6997. json_object *ExtendedTriggerMessage = json_object_new_object();
  6998. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6999. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7000. sprintf(message,"[%d,\"%s\",%s]"
  7001. ,MESSAGE_TYPE_CALLRESULT
  7002. ,uuid
  7003. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7004. json_object_put(ExtendedTriggerMessage);
  7005. LWS_Send(message);
  7006. return result;
  7007. }
  7008. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7009. {
  7010. mtrace();
  7011. int result = PASS;
  7012. char message[4096]={0};
  7013. json_object *GetInstalledCertificateIds = json_object_new_object();
  7014. json_object *certificateHashDataDatas = json_object_new_array();
  7015. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7016. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7017. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7018. {
  7019. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7020. {
  7021. json_object *certificateHashData = json_object_new_object();
  7022. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7023. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7024. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7025. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7026. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7027. }
  7028. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7029. }
  7030. else
  7031. {
  7032. json_object_put(certificateHashDataDatas);
  7033. }
  7034. sprintf(message,"[%d,\"%s\",%s]"
  7035. ,MESSAGE_TYPE_CALLRESULT
  7036. ,uuid
  7037. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7038. json_object_put(GetInstalledCertificateIds);
  7039. LWS_Send(message);
  7040. return result;
  7041. }
  7042. int sendGetLogConfirmation(char *uuid)
  7043. {
  7044. mtrace();
  7045. int result = PASS;
  7046. char message[4096]={0};
  7047. json_object *GetLog = json_object_new_object();
  7048. DEBUG_INFO("sendGetLogConfirmation...\n");
  7049. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7050. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7051. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7052. sprintf(message,"[%d,\"%s\",%s]"
  7053. ,MESSAGE_TYPE_CALLRESULT
  7054. ,uuid
  7055. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7056. json_object_put(GetLog);
  7057. LWS_Send(message);
  7058. return result;
  7059. }
  7060. int sendInstallCertificateConfirmation(char *uuid)
  7061. {
  7062. mtrace();
  7063. int result = PASS;
  7064. char message[4096]={0};
  7065. json_object *InstallCertificate = json_object_new_object();
  7066. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7067. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7068. sprintf(message,"[%d,\"%s\",%s]"
  7069. ,MESSAGE_TYPE_CALLRESULT
  7070. ,uuid
  7071. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7072. json_object_put(InstallCertificate);
  7073. LWS_Send(message);
  7074. return result;
  7075. }
  7076. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7077. {
  7078. mtrace();
  7079. int result = PASS;
  7080. char message[4096]={0};
  7081. json_object *SignedUpdateFirmware = json_object_new_object();
  7082. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7083. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7084. sprintf(message,"[%d,\"%s\",%s]"
  7085. ,MESSAGE_TYPE_CALLRESULT
  7086. ,uuid
  7087. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7088. json_object_put(SignedUpdateFirmware);
  7089. LWS_Send(message);
  7090. return result;
  7091. }
  7092. int sendUnknownConfirmation(char *uuid)
  7093. {
  7094. mtrace();
  7095. int result = PASS;
  7096. char message[256]={0};
  7097. DEBUG_INFO("sendUnknownConfirmation...\n");
  7098. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7099. LWS_Send(message);
  7100. return result;
  7101. }
  7102. //==========================================
  7103. // Handle server request routine Start
  7104. //==========================================
  7105. int handleCancelReservationRequest(char *uuid, char *payload)
  7106. {
  7107. mtrace();
  7108. int result = FAIL;
  7109. int gunNO = 0;
  7110. int reservationIdInt = -1;
  7111. char comfirmstr[20];
  7112. DEBUG_INFO("handleCancelReservationRequest...\n");
  7113. json_object *CancelReservation;
  7114. CancelReservation = json_tokener_parse(payload);
  7115. if(!is_error(CancelReservation))
  7116. {
  7117. // Required data
  7118. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7119. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7120. }
  7121. json_object_put(CancelReservation);
  7122. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7123. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7124. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7125. if(reservationIdInt != -1)
  7126. {
  7127. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7128. //check Transaction active
  7129. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7131. {
  7132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7133. {
  7134. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7135. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7136. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7137. {
  7138. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7139. }
  7140. else
  7141. {
  7142. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7143. }
  7144. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7145. goto end;
  7146. }
  7147. }
  7148. for (int index = 0; index < CCS_QUANTITY; index++)
  7149. {
  7150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7151. {
  7152. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7153. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7154. if(gunType[2] == GUN_TYPE_CCS)
  7155. {
  7156. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7157. }
  7158. else
  7159. {
  7160. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7161. }
  7162. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7163. goto end;
  7164. }
  7165. }
  7166. for (int index = 0; index < GB_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7169. {
  7170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7171. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7172. if(gunType[2] == GUN_TYPE_GBT)
  7173. {
  7174. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7175. }
  7176. else
  7177. {
  7178. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7179. }
  7180. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7181. goto end;
  7182. }
  7183. }
  7184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7187. {
  7188. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7189. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7190. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7191. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7192. goto end;
  7193. }
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7198. {
  7199. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7200. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7202. {
  7203. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7204. }
  7205. else
  7206. {
  7207. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7208. }
  7209. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7210. goto end;
  7211. }
  7212. }
  7213. }
  7214. //The reservationId does NOT match the reservationId
  7215. sendCancelReservationConfirmation(uuid, comfirmstr);
  7216. end:
  7217. // Fill in ocpp packet uuid
  7218. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7219. return result;
  7220. }
  7221. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7222. {
  7223. mtrace();
  7224. int result = FAIL;
  7225. int gunIndex = 0;
  7226. char typeStr[16]={0};
  7227. char comfirmstr[20];
  7228. int specificId = FALSE;
  7229. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7230. json_object *ChangeAvailability;
  7231. ChangeAvailability = json_tokener_parse(payload);
  7232. if(!is_error(ChangeAvailability))
  7233. {
  7234. // Required data
  7235. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7236. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7237. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7238. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7239. }
  7240. json_object_put(ChangeAvailability);
  7241. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7242. {
  7243. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7244. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7245. }
  7246. else if(gunIndex == 0)
  7247. {
  7248. for(int i=0; i < gunTotalNumber; i++)
  7249. {
  7250. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7251. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7252. }
  7253. }
  7254. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7255. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7256. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7257. {
  7258. specificId = TRUE;
  7259. }
  7260. if(specificId == FALSE)
  7261. goto end;
  7262. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7263. {
  7264. //----------------------gunIndex is 0 ------------------------------------------------//
  7265. if(gunIndex == 0)
  7266. {
  7267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7268. {
  7269. for(int i=0; i < gunTotalNumber; i++)
  7270. {
  7271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7272. {
  7273. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7274. {
  7275. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7276. {
  7277. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7278. goto end;
  7279. }
  7280. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7285. {
  7286. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7287. goto end;
  7288. }
  7289. }
  7290. }//END FOR CHAdeMO_QUANTITY
  7291. for (int index = 0; index < CCS_QUANTITY; index++)
  7292. {
  7293. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7294. {
  7295. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7296. {
  7297. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7298. goto end;
  7299. }
  7300. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7305. {
  7306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7307. goto end;
  7308. }
  7309. }
  7310. }//END FOR CCS_QUANTITY
  7311. for (int index = 0; index < GB_QUANTITY; index++)
  7312. {
  7313. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7314. {
  7315. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7316. {
  7317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7318. goto end;
  7319. }
  7320. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7321. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7322. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7323. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7325. {
  7326. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7327. goto end;
  7328. }
  7329. }
  7330. }// END FOR GB_QUANTITY
  7331. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7332. {
  7333. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7334. {
  7335. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7336. {
  7337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7338. goto end;
  7339. }
  7340. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7341. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7342. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7343. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7344. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7345. {
  7346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7347. goto end;
  7348. }
  7349. }
  7350. }// END FOR GENERAL_GUN_QUANTITY
  7351. for (int index = 0; index < AC_QUANTITY; index++)
  7352. {
  7353. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7354. {
  7355. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7356. {
  7357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7358. goto end;
  7359. }
  7360. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7363. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7364. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7365. {
  7366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7367. goto end;
  7368. }
  7369. }
  7370. }//END FOR AC_QUANTITY
  7371. }// END FOR gunTotalNumber
  7372. }
  7373. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7374. {
  7375. for(int i=0; i < gunTotalNumber; i++)
  7376. {
  7377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7378. {
  7379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7380. goto end;
  7381. }
  7382. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7383. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7385. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7386. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7387. {
  7388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7389. goto end;
  7390. }
  7391. }
  7392. }
  7393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7394. goto end;
  7395. }
  7396. //----------------------gunIndex is not 0 ------------------------------------------------//
  7397. //check Transaction active
  7398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7399. {
  7400. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7401. {
  7402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7403. {
  7404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7405. goto end;
  7406. }
  7407. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7412. {
  7413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7414. goto end;
  7415. }
  7416. else
  7417. {
  7418. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7420. goto end;
  7421. }
  7422. }
  7423. }//END FOR CHAdeMO_QUANTITY
  7424. for (int index = 0; index < CCS_QUANTITY; index++)
  7425. {
  7426. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7427. {
  7428. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7429. {
  7430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7431. goto end;
  7432. }
  7433. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7434. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7435. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7436. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7437. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7438. {
  7439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7440. goto end;
  7441. }
  7442. else
  7443. {
  7444. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7446. goto end;
  7447. }
  7448. }
  7449. }//END FOR CCS_QUANTITY
  7450. for (int index = 0; index < GB_QUANTITY; index++)
  7451. {
  7452. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7453. {
  7454. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7455. {
  7456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7457. goto end;
  7458. }
  7459. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7460. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7462. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7463. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7464. {
  7465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7466. goto end;
  7467. }
  7468. else
  7469. {
  7470. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7472. goto end;
  7473. }
  7474. }
  7475. }// END FOR GB_QUANTITY
  7476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7477. {
  7478. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7479. {
  7480. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7481. {
  7482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7483. goto end;
  7484. }
  7485. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7486. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7488. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7489. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7490. {
  7491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7492. goto end;
  7493. }
  7494. else
  7495. {
  7496. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7498. goto end;
  7499. }
  7500. }
  7501. }// END FOR GENERAL_GUN_QUANTITY
  7502. for (int index = 0; index < AC_QUANTITY; index++)
  7503. {
  7504. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7505. {
  7506. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7507. {
  7508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7509. goto end;
  7510. }
  7511. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7514. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7515. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7516. {
  7517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7518. goto end;
  7519. }
  7520. else
  7521. {
  7522. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7524. goto end;
  7525. }
  7526. }
  7527. }//END FOR AC_QUANTITY
  7528. }//END FOR AvailabilityTypeStr[Inoperative]
  7529. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7530. {
  7531. //----------------------gunIndex is 0 ------------------------------------------------//
  7532. if(gunIndex == 0)
  7533. {
  7534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7535. {
  7536. for(int i=0; i < gunTotalNumber; i++)
  7537. {
  7538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7539. {
  7540. 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
  7541. {
  7542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7543. goto end;
  7544. }
  7545. }//END FOR CHAdeMO_QUANTITY
  7546. for (int index = 0; index < CCS_QUANTITY; index++)
  7547. {
  7548. 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
  7549. {
  7550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7551. goto end;
  7552. }
  7553. }//END FOR CCS_QUANTITY
  7554. for (int index = 0; index < GB_QUANTITY; index++)
  7555. {
  7556. 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
  7557. {
  7558. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7560. goto end;
  7561. }
  7562. }// END FOR GB_QUANTITY
  7563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7564. {
  7565. 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
  7566. {
  7567. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7569. goto end;
  7570. }
  7571. }// END FOR GENERAL_GUN_QUANTITY
  7572. for (int index = 0; index < AC_QUANTITY; index++)
  7573. {
  7574. 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
  7575. {
  7576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7577. goto end;
  7578. }
  7579. }//END FOR CHAdeMO_QUANTITY
  7580. }// END FOR gunTotalNumber
  7581. }
  7582. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7583. {
  7584. for(int i=0; i < gunTotalNumber; i++)
  7585. {
  7586. for (int index = 0; index < AC_QUANTITY; index++)
  7587. {
  7588. 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
  7589. {
  7590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7591. goto end;
  7592. }
  7593. }//END FOR CHAdeMO_QUANTITY
  7594. } // END FOR gunTotalNumber
  7595. }
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7597. goto end;
  7598. }
  7599. //----------------------gunIndex is not 0 ------------------------------------------------//
  7600. //check Transaction active
  7601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7602. {
  7603. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7604. {
  7605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7606. goto end;
  7607. }
  7608. }//END FOR CHAdeMO_QUANTITY
  7609. for (int index = 0; index < CCS_QUANTITY; index++)
  7610. {
  7611. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7612. {
  7613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7614. goto end;
  7615. }
  7616. }//END FOR CCS_QUANTITY
  7617. for (int index = 0; index < GB_QUANTITY; index++)
  7618. {
  7619. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7620. {
  7621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7622. goto end;
  7623. }
  7624. }// END FOR GB_QUANTITY
  7625. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7626. {
  7627. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7628. {
  7629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7630. goto end;
  7631. }
  7632. }// END FOR GENERAL_GUN_QUANTITY
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7636. {
  7637. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7638. goto end;
  7639. }
  7640. }//END FOR AC_QUANTITY
  7641. }//END FOR AvailabilityTypeStr[Operative]
  7642. end:
  7643. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7644. {
  7645. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7646. }
  7647. else
  7648. {
  7649. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7650. }
  7651. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7652. {
  7653. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7654. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7655. }
  7656. else if(gunIndex == 0)
  7657. {
  7658. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7659. {
  7660. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7661. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7662. }
  7663. }
  7664. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7665. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7666. return result;
  7667. }
  7668. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7669. {
  7670. mtrace();
  7671. int result = FAIL;
  7672. char keystr[40]={0};
  7673. char valuestr[256]={0};
  7674. char comfirmstr[20]={0};
  7675. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7676. json_object *ChangeConfiguration;
  7677. ChangeConfiguration = json_tokener_parse(payload);
  7678. if(!is_error(ChangeConfiguration))
  7679. {
  7680. // Required data
  7681. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7682. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7683. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7684. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7685. }
  7686. json_object_put(ChangeConfiguration);
  7687. if((uuid==NULL) || (payload ==NULL) )
  7688. {
  7689. DEBUG_ERROR("Payload is null\n");
  7690. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7691. }
  7692. else
  7693. {
  7694. int status = setKeyValue(keystr, valuestr);
  7695. switch(status)
  7696. {
  7697. case ConfigurationStatus_Accepted:
  7698. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7699. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7700. StoreConfigurationTable();
  7701. break;
  7702. case RebootRequired:
  7703. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7704. StoreConfigurationTable();
  7705. break;
  7706. case NotSupported:
  7707. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7708. break;
  7709. case ConfigurationStatus_Rejected:
  7710. default:
  7711. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7712. break;
  7713. }
  7714. }
  7715. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7716. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7717. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7718. {
  7719. ChageWebSocketPingInterval(atoi(valuestr));
  7720. }
  7721. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7722. {
  7723. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7724. SetOcppConnStatus(FALSE);
  7725. }
  7726. return result;
  7727. }
  7728. int handleClearCacheRequest(char *uuid, char *payload)
  7729. {
  7730. mtrace();
  7731. int result = FAIL;
  7732. char comfirmstr[20];
  7733. char rmFileCmd[100]={0};
  7734. struct stat stats;
  7735. DEBUG_INFO("handleClearCacheRequest...\n");
  7736. stat("/Storage/OCPP_PH", &stats);
  7737. // Check for directory existence
  7738. if (S_ISDIR(stats.st_mode) == 1)
  7739. {}
  7740. else
  7741. {
  7742. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7743. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7744. system(rmFileCmd);
  7745. }
  7746. if(OCPP_cleanLocalCache())
  7747. {
  7748. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7749. }
  7750. else
  7751. {
  7752. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7753. }
  7754. sendClearCacheConfirmation(uuid, comfirmstr);
  7755. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7756. return result;
  7757. }
  7758. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7759. {
  7760. mtrace();
  7761. int result = FAIL;
  7762. int resultRename;
  7763. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7764. char chargingProfilePurposeStr[26]={0};
  7765. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7766. char tempchargingProfilePurposeStr[26]={0};
  7767. char str[100]={0};
  7768. char fname[200]={0};
  7769. char comfirmstr[20]={0};
  7770. char word[1600]={0};
  7771. int clearflag = FALSE;
  7772. int chargingProfileIdIsNULL = FALSE;
  7773. int connectorIsNULL = FALSE;
  7774. int chargingProfilePurposeIsNULL = FALSE;
  7775. int stackLevelIsNULL = FALSE;
  7776. //int GotoEnd = FALSE;
  7777. FILE *fptr1, *fptr2;
  7778. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7779. int n_chargingProfile=0;
  7780. int isEmptyFile = FALSE;
  7781. char sLineWord[1600]={0};
  7782. char chargingProfiles[10][100]={0};
  7783. int ChargeProfileCount = 0;
  7784. int ch;
  7785. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7786. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7787. json_object *ClearChargingProfile;
  7788. ClearChargingProfile = json_tokener_parse(payload);
  7789. if(!is_error(ClearChargingProfile))
  7790. {
  7791. // Optional data
  7792. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7793. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7794. else
  7795. chargingProfileIdIsNULL = TRUE;
  7796. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7797. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7798. else
  7799. connectorIsNULL = TRUE;
  7800. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7801. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7802. else
  7803. chargingProfilePurposeIsNULL = TRUE;
  7804. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7805. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7806. else
  7807. stackLevelIsNULL = TRUE;
  7808. }
  7809. json_object_put(ClearChargingProfile);
  7810. if(connectorIsNULL == FALSE)
  7811. {
  7812. switch(connectorIdInt)
  7813. {
  7814. case 0:
  7815. if(chargingProfilePurposeIsNULL == TRUE)
  7816. {
  7817. int l = 0;
  7818. strcpy(fname, ChargePointMaxProfile_JSON);
  7819. if((access(fname,F_OK))!=-1)
  7820. {
  7821. strcpy(chargingProfiles[l], fname);
  7822. l = l + 1;
  7823. }
  7824. strcpy(fname, TxDefaultProfile_0_JSON);
  7825. if((access(fname,F_OK))!=-1)
  7826. {
  7827. strcpy(chargingProfiles[l], fname);
  7828. l = l + 1;
  7829. }
  7830. ChargeProfileCount = l;
  7831. }
  7832. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7833. {
  7834. strcpy(fname, ChargePointMaxProfile_JSON);
  7835. if((access(fname,F_OK))!=-1)
  7836. {
  7837. strcpy(chargingProfiles[0], fname);
  7838. ChargeProfileCount = 1;
  7839. }
  7840. }
  7841. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7842. {
  7843. strcpy(fname, TxDefaultProfile_0_JSON);
  7844. if((access(fname,F_OK))!=-1)
  7845. {
  7846. strcpy(chargingProfiles[0], fname);
  7847. ChargeProfileCount = 1;
  7848. }
  7849. }
  7850. break;
  7851. default:
  7852. if(chargingProfilePurposeIsNULL == TRUE)
  7853. {
  7854. int m = 0;
  7855. memset(fname, 0, ARRAY_SIZE(fname));
  7856. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7857. if((access(fname,F_OK))!=-1)
  7858. {
  7859. strcpy(chargingProfiles[m], fname);
  7860. m = m + 1;
  7861. }
  7862. memset(fname, 0, ARRAY_SIZE(fname));
  7863. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7864. if((access(fname,F_OK))!=-1)
  7865. {
  7866. strcpy(chargingProfiles[m], fname);
  7867. m = m + 1;
  7868. }
  7869. ChargeProfileCount = m;
  7870. }
  7871. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7872. {
  7873. //strcpy(fname, TxDefaultProfile_1_JSON);
  7874. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7875. if((access(fname,F_OK))!=-1)
  7876. {
  7877. strcpy(chargingProfiles[0], fname);
  7878. ChargeProfileCount = 1;
  7879. }
  7880. }
  7881. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7882. {
  7883. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7884. if((access(fname,F_OK))!=-1)
  7885. {
  7886. strcpy(chargingProfiles[0], fname);
  7887. ChargeProfileCount = 1;
  7888. }
  7889. //strcpy(fname, TxProfile_1_JSON);
  7890. }
  7891. //strcpy(fname, ChargePointMaxProfile_JSON );
  7892. break;
  7893. }
  7894. }
  7895. else // Check all Charging Profiles
  7896. {
  7897. int i = 0;
  7898. char fnametemp[200]={0};
  7899. ChargeProfileCount = 0;
  7900. //Check ChargePointMaxProfile.json exit
  7901. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7902. {
  7903. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7904. i = i + 1;
  7905. }
  7906. //Check TxDefaultProfile_0.json exit
  7907. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7908. {
  7909. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7910. i = i + 1;
  7911. }
  7912. //Check TxDefaultProfile_%d.json
  7913. for(int j=1; j <= gunTotalNumber; j++)
  7914. {
  7915. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7916. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7917. if((access(fnametemp,F_OK))!=-1)
  7918. {
  7919. strcpy(chargingProfiles[i], fnametemp);
  7920. i = i + 1;
  7921. }
  7922. }
  7923. //Check TxProfile_%d.json
  7924. for(int j=1; j <= gunTotalNumber; j++)
  7925. {
  7926. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7927. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7928. if((access(fnametemp,F_OK))!=-1)
  7929. {
  7930. strcpy(chargingProfiles[i], fnametemp);
  7931. i = i + 1;
  7932. }
  7933. }
  7934. ChargeProfileCount = i;
  7935. }// End connectorIsNULL is TRUE
  7936. if(ChargeProfileCount == 0)
  7937. {
  7938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7939. goto end;
  7940. }
  7941. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7942. {
  7943. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7944. goto end;
  7945. }
  7946. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7947. {
  7948. memset(str, 0, ARRAY_SIZE(str));
  7949. // clear temp file
  7950. sprintf(str,"rm -f %s",temp);
  7951. system(str);
  7952. for(int k=0; k < ChargeProfileCount; k++)
  7953. {
  7954. memset(str, 0, ARRAY_SIZE(str));
  7955. //clear file in C
  7956. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7957. system(str);
  7958. }
  7959. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7960. goto end;
  7961. }
  7962. else if(connectorIsNULL == TRUE)
  7963. {
  7964. for(int k=0; k < ChargeProfileCount; k++)
  7965. {
  7966. fptr1 = fopen(chargingProfiles[k], "r");
  7967. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7968. //Check Charging Profile Count
  7969. while(fscanf(fptr1, "%s", word) != EOF)
  7970. {
  7971. //DEBUG_INFO("word=%s\n",word);
  7972. if(strstr(word, "chargingProfileId")!= NULL)
  7973. {
  7974. //DEBUG_INFO("test chargingProfileId \n");
  7975. n_chargingProfile = n_chargingProfile + 1;
  7976. //DEBUG_INFO("chargingProfileId Found\n");
  7977. }
  7978. }
  7979. rewind(fptr1);
  7980. //search Charging Profile Element
  7981. //int i= 0;
  7982. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7983. {
  7984. json_object *tmpProfilee;
  7985. tmpProfilee = json_tokener_parse(sLineWord);
  7986. if(!is_error(tmpProfilee))
  7987. {
  7988. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7989. {
  7990. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7991. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7992. }
  7993. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7994. {
  7995. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7996. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7997. }
  7998. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7999. {
  8000. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8001. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8002. }
  8003. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8004. {
  8005. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8006. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8007. }
  8008. }
  8009. json_object_put(tmpProfilee);
  8010. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8011. {
  8012. //------- not write to fptr2-------//
  8013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8014. //clearflag = TRUE;
  8015. }
  8016. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8017. {
  8018. //------- not write to fptr2-------//
  8019. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8020. }
  8021. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8022. {
  8023. //------- not write to fptr2-------//
  8024. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8025. }
  8026. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8027. {
  8028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8029. }
  8030. else
  8031. {
  8032. fprintf(fptr2, sLineWord);//writing data into file
  8033. }
  8034. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8035. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8036. if(clearflag == TRUE)
  8037. {
  8038. fclose(fptr1);
  8039. fclose(fptr2);
  8040. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8041. system(str);
  8042. // clear temp file
  8043. sprintf(str,"rm -f %s",temp);
  8044. system(str);
  8045. }
  8046. else
  8047. {
  8048. fclose(fptr1);
  8049. fclose(fptr2);
  8050. memset(str, 0, ARRAY_SIZE(str));
  8051. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8052. system(str);
  8053. resultRename = rename(temp, chargingProfiles[k]);
  8054. if(resultRename == 0)
  8055. {
  8056. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8057. }
  8058. else
  8059. {
  8060. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8061. }
  8062. if(comfirmstr[0]== 0)
  8063. {
  8064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8065. }
  8066. //Check chargingProfile is empty file
  8067. /*------ Read the file ----------------*/
  8068. fptr1=fopen(chargingProfiles[k],"r");
  8069. ch=fgetc(fptr1);
  8070. rewind(fptr1);
  8071. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8072. if(ch!=EOF)
  8073. {
  8074. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8075. {
  8076. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8077. if(sLineWord[0]=='\0')
  8078. {
  8079. isEmptyFile = TRUE;
  8080. break;
  8081. }
  8082. else
  8083. {
  8084. isEmptyFile = FALSE;
  8085. break;
  8086. }
  8087. }
  8088. }
  8089. else
  8090. isEmptyFile = TRUE;
  8091. fclose(fptr1);
  8092. if(isEmptyFile == TRUE)
  8093. {
  8094. memset(str, 0, ARRAY_SIZE(str));
  8095. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8096. system(str);
  8097. }
  8098. }
  8099. }// End of while(int k=0; k < ChargePointCount; k++)
  8100. }
  8101. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8102. {
  8103. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8104. for(int k=0; k < ChargeProfileCount; k++)
  8105. {
  8106. fptr1 = fopen(chargingProfiles[k], "r");
  8107. fptr2 = fopen(temp, "w+");
  8108. //Check Charging Profile Count
  8109. while(fscanf(fptr1, "%s", word) != EOF)
  8110. {
  8111. //DEBUG_INFO("word=%s\n",word);
  8112. if(strstr(word, "chargingProfileId")!= NULL)
  8113. {
  8114. n_chargingProfile = n_chargingProfile + 1;
  8115. }
  8116. }
  8117. rewind(fptr1);
  8118. //search Charging Profile Element
  8119. //int i= 0;
  8120. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8121. {
  8122. json_object *tmpProfilee;
  8123. tmpProfilee = json_tokener_parse(sLineWord);
  8124. if(!is_error(tmpProfilee))
  8125. {
  8126. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8127. {
  8128. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8129. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8130. }
  8131. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8132. {
  8133. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8134. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8135. }
  8136. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8137. {
  8138. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8139. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8140. }
  8141. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8142. {
  8143. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8144. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8145. }
  8146. }
  8147. json_object_put(tmpProfilee);
  8148. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8149. {
  8150. //------- not write to fptr2-------//
  8151. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8152. //clearflag = TRUE;
  8153. }
  8154. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8155. {
  8156. //------- not write to fptr2-------//
  8157. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8158. }
  8159. else if(stackLevelIsNULL == TRUE)
  8160. {
  8161. //Clear Whole File
  8162. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8163. clearflag = TRUE;
  8164. break;
  8165. }
  8166. else
  8167. {
  8168. fprintf(fptr2, sLineWord);//writing data into file
  8169. }
  8170. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8171. }
  8172. if(clearflag == TRUE)
  8173. {
  8174. fclose(fptr1);
  8175. fclose(fptr2);
  8176. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8177. system(str);
  8178. // clear temp file
  8179. sprintf(str,"rm -f %s",temp);
  8180. system(str);
  8181. }
  8182. else
  8183. {
  8184. fclose(fptr1);
  8185. fclose(fptr2);
  8186. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8187. system(str);
  8188. resultRename = rename(temp, chargingProfiles[k]);
  8189. if(resultRename == 0)
  8190. {
  8191. DEBUG_INFO("File ChargingProfile renamed successfully");
  8192. }
  8193. else
  8194. {
  8195. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8196. }
  8197. if(comfirmstr[0]== 0)
  8198. {
  8199. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8200. }
  8201. //Check chargingProfile is empty file
  8202. /*------ Read the file ----------------*/
  8203. fptr1=fopen(chargingProfiles[k],"r");
  8204. ch=fgetc(fptr1);
  8205. rewind(fptr1);
  8206. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8207. if(ch!=EOF)
  8208. {
  8209. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8210. {
  8211. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8212. if(sLineWord[0]=='\0')
  8213. {
  8214. isEmptyFile = TRUE;
  8215. break;
  8216. }
  8217. else
  8218. {
  8219. isEmptyFile = FALSE;
  8220. break;
  8221. }
  8222. }
  8223. }
  8224. else
  8225. isEmptyFile = TRUE;
  8226. fclose(fptr1);
  8227. if(isEmptyFile == TRUE)
  8228. {
  8229. memset(str, 0, ARRAY_SIZE(str));
  8230. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8231. system(str);
  8232. }
  8233. /*------- End of reading ---------------*/
  8234. }
  8235. } // while(int k=0; k < ChargeProfileCount; k++)
  8236. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8237. end:
  8238. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8239. {
  8240. if(connectorIdInt == 0)
  8241. {
  8242. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8243. {
  8244. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8245. }
  8246. }
  8247. else
  8248. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8249. }
  8250. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8251. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8252. return result;
  8253. }
  8254. void createFirmwareVersionByDataTransfer(void)
  8255. {
  8256. json_object *FirmwareDataTransfer = json_object_new_object();
  8257. // AC & DC model
  8258. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8259. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8260. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8261. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8262. // DC model
  8263. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8264. {
  8265. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8266. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8267. (gunType[3] != GUN_TYPE_UNKNOWN))
  8268. {
  8269. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8270. }
  8271. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8272. {
  8273. // DS DM DW
  8274. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8275. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8276. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8277. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8278. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8279. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8280. }
  8281. else
  8282. {
  8283. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8284. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8285. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8286. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8287. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8288. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8289. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8290. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8291. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8292. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8293. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8294. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8295. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8296. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8297. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8298. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8299. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8300. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8301. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8302. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8303. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8304. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8305. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8306. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8307. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8308. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8309. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8310. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8311. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8312. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8313. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8314. }
  8315. }
  8316. // 4G model
  8317. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8318. {
  8319. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8320. }
  8321. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8322. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8323. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8324. json_object_put(FirmwareDataTransfer);
  8325. }
  8326. int handleDataTransferRequest(char *uuid, char *payload)
  8327. {
  8328. mtrace();
  8329. json_object *response = json_object_new_object();
  8330. int result = FAIL;
  8331. char tempvendorId[255]={0};
  8332. char tempmessageId[50]={0};
  8333. char tempdata[512]={0};
  8334. char message[2048]={0};
  8335. DEBUG_INFO("handleDataTransferRequest...\n");
  8336. if((uuid != NULL) && (payload != NULL))
  8337. {
  8338. json_object *DataTransfer;
  8339. DataTransfer = json_tokener_parse(payload);
  8340. if(!is_error(DataTransfer))
  8341. {
  8342. // Required data
  8343. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8344. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8345. // Optional data
  8346. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8347. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8348. if(json_object_object_get(DataTransfer, "data") != NULL)
  8349. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8350. result = PASS;
  8351. }
  8352. json_object_put(DataTransfer);
  8353. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8354. {
  8355. // Send all moudle firmware version on EVSE
  8356. createFirmwareVersionByDataTransfer();
  8357. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8358. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8359. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8360. json_object_put(response);
  8361. }
  8362. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8363. {
  8364. system("/usr/bin/run_tmate_restart.sh &");
  8365. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8366. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8367. json_object_put(response);
  8368. }
  8369. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8370. {
  8371. json_object *data;
  8372. data = json_tokener_parse(tempdata);
  8373. if(!is_error(data))
  8374. {
  8375. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8376. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8377. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8378. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8379. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8380. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8381. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8382. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8383. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8384. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8385. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8386. }
  8387. else
  8388. {
  8389. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8390. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8391. }
  8392. json_object_put(data);
  8393. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8394. json_object_put(response);
  8395. }
  8396. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8397. {
  8398. json_object *data;
  8399. data = json_tokener_parse(tempdata);
  8400. if(!is_error(data))
  8401. {
  8402. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8403. if(json_object_object_get(data, "idToken") != NULL)
  8404. {
  8405. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8406. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8407. }
  8408. if(json_object_object_get(data, "price") != NULL)
  8409. {
  8410. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8411. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8412. }
  8413. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8414. }
  8415. else
  8416. {
  8417. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8418. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8419. }
  8420. json_object_put(data);
  8421. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8422. json_object_put(response);
  8423. }
  8424. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8425. {
  8426. json_object *data;
  8427. data = json_tokener_parse(tempdata);
  8428. if(!is_error(data))
  8429. {
  8430. if(json_object_object_get(data, "txId") != NULL)
  8431. {
  8432. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8433. for(int idx = 0;idx<gunTotalNumber;idx++)
  8434. {
  8435. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8436. {
  8437. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8438. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8439. if(json_object_object_get(data, "description") != NULL)
  8440. {
  8441. // California pricing V1.0
  8442. DEBUG_INFO("California pricing V1.0\n");
  8443. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8444. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8445. }
  8446. else
  8447. {
  8448. // California pricing V1.1
  8449. DEBUG_INFO("California pricing V1.1\n");
  8450. if(json_object_object_get(data, "timestamp") != NULL)
  8451. {
  8452. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8453. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8454. }
  8455. if(json_object_object_get(data, "meterValue") != NULL)
  8456. {
  8457. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8458. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8459. }
  8460. if(json_object_object_get(data, "cost") != NULL)
  8461. {
  8462. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8463. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8464. }
  8465. if(json_object_object_get(data, "state") != NULL)
  8466. {
  8467. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8468. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8469. }
  8470. if(json_object_object_get(data, "chargingPrice") != NULL)
  8471. {
  8472. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8473. {
  8474. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8475. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8476. }
  8477. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8478. {
  8479. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8480. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8481. }
  8482. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8483. {
  8484. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8485. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8486. }
  8487. }
  8488. if(json_object_object_get(data, "idlePrice") != NULL)
  8489. {
  8490. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8491. {
  8492. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8493. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8494. }
  8495. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8496. {
  8497. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8498. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8499. }
  8500. }
  8501. if(json_object_object_get(data, "nextPeriod") != NULL)
  8502. {
  8503. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8504. {
  8505. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8506. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8507. }
  8508. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8509. {
  8510. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8511. {
  8512. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  8513. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  8514. }
  8515. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8516. {
  8517. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  8518. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  8519. }
  8520. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8521. {
  8522. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  8523. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  8524. }
  8525. }
  8526. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8527. {
  8528. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8529. {
  8530. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  8531. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  8532. }
  8533. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8534. {
  8535. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  8536. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  8537. }
  8538. }
  8539. }
  8540. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8541. {
  8542. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8543. {
  8544. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8545. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8546. }
  8547. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8548. {
  8549. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8550. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8551. }
  8552. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8553. {
  8554. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8555. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8556. }
  8557. }
  8558. }
  8559. }
  8560. }
  8561. }
  8562. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8563. }
  8564. else
  8565. {
  8566. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8567. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8568. }
  8569. json_object_put(data);
  8570. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8571. json_object_put(response);
  8572. }
  8573. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8574. {
  8575. json_object *data;
  8576. data = json_tokener_parse(tempdata);
  8577. if(!is_error(data))
  8578. {
  8579. if(json_object_object_get(data, "txId") != NULL)
  8580. {
  8581. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8582. for(int idx = 0;idx<gunTotalNumber;idx++)
  8583. {
  8584. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8585. {
  8586. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8587. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8588. if(json_object_object_get(data, "description") != NULL)
  8589. {
  8590. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8591. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8592. }
  8593. }
  8594. }
  8595. }
  8596. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8597. }
  8598. else
  8599. {
  8600. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8601. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8602. }
  8603. json_object_put(data);
  8604. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8605. json_object_put(response);
  8606. }
  8607. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8608. {
  8609. json_object *data;
  8610. data = json_tokener_parse(tempdata);
  8611. if(!is_error(data))
  8612. {
  8613. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8614. if(json_object_object_get(data, "Content_Type") != NULL)
  8615. {
  8616. 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))
  8617. {
  8618. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8619. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8620. {
  8621. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8622. }
  8623. }
  8624. else
  8625. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8626. }
  8627. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8628. }
  8629. else
  8630. {
  8631. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8632. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8633. }
  8634. json_object_put(data);
  8635. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8636. json_object_put(response);
  8637. }
  8638. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8639. {
  8640. json_object *data;
  8641. data = json_tokener_parse(tempdata);
  8642. if(!is_error(data))
  8643. {
  8644. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8645. if(json_object_object_get(data, "Page_Index") != NULL)
  8646. {
  8647. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8648. }
  8649. if(json_object_object_get(data, "Duration") != NULL)
  8650. {
  8651. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8652. }
  8653. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8654. }
  8655. else
  8656. {
  8657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8658. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8659. }
  8660. json_object_put(data);
  8661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8662. json_object_put(response);
  8663. }
  8664. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8665. {
  8666. json_object *data;
  8667. data = json_tokener_parse(tempdata);
  8668. if(!is_error(data))
  8669. {
  8670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8671. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8672. {
  8673. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8674. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8675. else
  8676. {
  8677. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8678. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8679. }
  8680. }
  8681. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8682. {
  8683. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8684. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8685. else
  8686. {
  8687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8688. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8689. }
  8690. }
  8691. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8692. {
  8693. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8694. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8695. else
  8696. {
  8697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8699. }
  8700. }
  8701. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8702. {
  8703. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8704. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8705. else
  8706. {
  8707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8708. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8709. }
  8710. }
  8711. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8712. {
  8713. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8714. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8715. else
  8716. {
  8717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8718. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8719. }
  8720. }
  8721. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8722. {
  8723. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8724. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8725. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8726. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8727. else
  8728. {
  8729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8731. }
  8732. }
  8733. if(json_object_object_get(data, "isAuthentication") != NULL)
  8734. {
  8735. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8736. {
  8737. case 0:
  8738. case 1:
  8739. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8740. break;
  8741. default:
  8742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8743. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8744. break;
  8745. }
  8746. }
  8747. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8748. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8749. }
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8754. }
  8755. json_object_put(data);
  8756. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8757. json_object_put(response);
  8758. }
  8759. else
  8760. {
  8761. // Can not find valid message id
  8762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8763. }
  8764. }
  8765. else
  8766. {
  8767. // Payload is null
  8768. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8769. }
  8770. LWS_Send(message);
  8771. return result;
  8772. }
  8773. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8774. {
  8775. mtrace();
  8776. int result = FAIL;
  8777. int connectorIdInt, durationInt;
  8778. char chargingRateUnitStr[4]={0};
  8779. char comfirmstr[20];
  8780. int confirmPeriods = 0;
  8781. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8782. json_object *GetCompositeSchedule;
  8783. GetCompositeSchedule = json_tokener_parse(payload);
  8784. if(!is_error(GetCompositeSchedule))
  8785. {
  8786. // Required data
  8787. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8788. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8789. else
  8790. connectorIdInt = -1;
  8791. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8792. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8793. else
  8794. durationInt = 86400;
  8795. // Optional data
  8796. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8797. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8798. }
  8799. json_object_put(GetCompositeSchedule);
  8800. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8801. if((connectorIdInt == 0) ||
  8802. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8803. {
  8804. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8805. struct StructChargingProfile tmpProfile[1];
  8806. if(strstr(chargingRateUnitStr, "W") != NULL)
  8807. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8808. else
  8809. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8810. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8811. {
  8812. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8813. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8814. }
  8815. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8816. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8817. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8818. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8819. {
  8820. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8821. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8822. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8823. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8824. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8825. {
  8826. confirmPeriods = idx;
  8827. break;
  8828. }
  8829. }
  8830. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8831. {
  8832. confirmPeriods += 1;
  8833. }
  8834. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8835. }
  8836. else
  8837. {
  8838. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8839. }
  8840. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8841. return result;
  8842. }
  8843. int handleGetConfigurationRequest(char *uuid, char *payload)
  8844. {
  8845. mtrace();
  8846. int result = FAIL;
  8847. int MaxKeySupported = 0;
  8848. int n_keys = 0;
  8849. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8850. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8851. json_object *GetConfiguration;
  8852. GetConfiguration = json_tokener_parse(payload);
  8853. if(!is_error(GetConfiguration))
  8854. {
  8855. // Optional data
  8856. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8857. {
  8858. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8859. {
  8860. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8861. n_keys = idx + 1;
  8862. }
  8863. }
  8864. }
  8865. json_object_put(GetConfiguration);
  8866. UnknownKeynum = 0;
  8867. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8868. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8869. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8870. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8871. if(n_keys != 0)
  8872. {
  8873. for(int i=0;i<n_keys;i++)
  8874. {
  8875. getKeyValue(requestKey[i]);
  8876. }
  8877. }
  8878. else
  8879. {
  8880. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8881. getKeyValue("");
  8882. }
  8883. processUnkownKey();
  8884. sendGetConfigurationConfirmation(uuid);
  8885. return result;
  8886. }
  8887. static char fnamePlusPath[100]={0};
  8888. static char fnamePWithNoPath[60]={0};
  8889. void checkUploadLog(void)
  8890. {
  8891. FILE *fp;
  8892. /* Open the command for reading. */
  8893. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8894. if (fp == NULL) {
  8895. DEBUG_WARN("Failed to run command\n" );
  8896. exit(1);
  8897. }
  8898. int ftppathlen = 0;
  8899. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8900. int i = 0;
  8901. /* Read the output a line at a time - output it. */
  8902. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8903. if(i==0)
  8904. {
  8905. ftppathlen = strlen(fnamePlusPath);
  8906. DEBUG_INFO("%s\n", fnamePlusPath);
  8907. fnamePlusPath[ftppathlen]='\0';
  8908. break;
  8909. }
  8910. i= i+1;
  8911. }
  8912. /* close */
  8913. pclose(fp);
  8914. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8915. {
  8916. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8917. {
  8918. fnamePlusPath[k]='\0';
  8919. }
  8920. }
  8921. i=1;
  8922. //char fname[60]={0};
  8923. while(i < ftppathlen)
  8924. {
  8925. int len=ftppathlen-i;
  8926. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8927. {
  8928. DEBUG_INFO("compare '/' all right\n");
  8929. break;
  8930. }
  8931. i=i+1;
  8932. }
  8933. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8934. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8935. fnamePWithNoPath[i+1] = '\0';
  8936. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8937. {
  8938. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8939. {
  8940. fnamePWithNoPath[j]='\0';
  8941. }
  8942. }
  8943. FILE* fp1 = fopen(fnamePlusPath, "r");
  8944. if (fp1)
  8945. {
  8946. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8947. // file exists
  8948. fclose(fp1);
  8949. }
  8950. else
  8951. {
  8952. // file doesn't exist
  8953. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8954. }
  8955. }
  8956. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8957. {
  8958. mtrace();
  8959. int result = FAIL;
  8960. time_t CurrentTime;
  8961. struct tm *tm;
  8962. pthread_t th_Status;
  8963. CurrentTime = time(NULL);
  8964. tm = localtime(&CurrentTime);
  8965. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8966. 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);
  8967. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8968. if(!interLock.isGetDiagnosticGoing)
  8969. {
  8970. interLock.isGetDiagnosticGoing = 1;
  8971. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8972. sleep(1);
  8973. }
  8974. else
  8975. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8976. return result;
  8977. }
  8978. void* GetDiagnosticsProcess(void* data)
  8979. {
  8980. pthread_detach(pthread_self());
  8981. mtrace();
  8982. int retriesInt=0, retryIntervalInt=0;
  8983. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8984. 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};
  8985. int port=0;
  8986. int isSuccess = FALSE;
  8987. char ftpbuf[200]={0};
  8988. char cmdBuf[2048];
  8989. struct tm *tmNow;
  8990. time_t CurrentTime;
  8991. struct tm tmStart;
  8992. struct tm tmStop;
  8993. CurrentTime = time(NULL);
  8994. tmNow=localtime(&CurrentTime);
  8995. uint16_t targetYear, targetMonth;
  8996. json_object *GetDiagnostics;
  8997. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8998. GetDiagnostics = json_tokener_parse(data);
  8999. if(!is_error(GetDiagnostics))
  9000. {
  9001. // Required data
  9002. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9003. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9004. // Optional data
  9005. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9006. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9007. else
  9008. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9009. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9010. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9011. else
  9012. retryIntervalInt = 30;
  9013. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9014. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9015. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9016. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9017. }
  9018. json_object_put(GetDiagnostics);
  9019. // Pack log to compress file
  9020. 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) &&
  9021. (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))
  9022. {
  9023. // Pack system log
  9024. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9025. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9026. targetYear = tmStart.tm_year;
  9027. targetMonth = tmStart.tm_mon;
  9028. do
  9029. {
  9030. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9031. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9032. if(targetMonth+1>=13)
  9033. {
  9034. targetYear += 1;
  9035. targetMonth = 1;
  9036. }
  9037. else
  9038. {
  9039. targetMonth += 1;
  9040. }
  9041. }while((targetYear < (tmNow->tm_year+1900)) ||
  9042. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9043. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9044. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9045. system(cmdBuf);
  9046. // Pack charging & event log
  9047. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9048. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9049. targetYear = tmStart.tm_year;
  9050. targetMonth = tmStart.tm_mon;
  9051. do
  9052. {
  9053. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9054. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9055. if(targetMonth+1>=13)
  9056. {
  9057. targetYear += 1;
  9058. targetMonth = 1;
  9059. }
  9060. else
  9061. {
  9062. targetMonth += 1;
  9063. }
  9064. }while((targetYear < (tmNow->tm_year+1900)) ||
  9065. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9066. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9067. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9068. system(cmdBuf);
  9069. // Combine log file
  9070. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9071. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9072. }
  9073. else
  9074. {
  9075. system("exec /root/logPackTools 'log' 6");
  9076. }
  9077. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9078. system(cmdBuf);
  9079. checkUploadLog();
  9080. //****************location*******************/
  9081. if(strcmp(locationstr,"")==0)
  9082. {
  9083. DEBUG_INFO("location is <Empty>!\n");
  9084. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9085. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9086. goto end;
  9087. }
  9088. memset(protocol, 0, ARRAY_SIZE(protocol));
  9089. memset(user, 0, ARRAY_SIZE(user) );
  9090. memset(password, 0, ARRAY_SIZE(password));
  9091. memset(host, 0, ARRAY_SIZE(host));
  9092. memset(path, 0, ARRAY_SIZE(path));
  9093. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9094. memset(host1, 0, ARRAY_SIZE(host1));
  9095. memset(path1, 0, ARRAY_SIZE(path1));
  9096. /*location: ftp://user:password@host:port/path*/
  9097. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9098. if((access(fnamePlusPath,F_OK))!=-1)
  9099. {
  9100. DEBUG_INFO("fnamePlusPath exist.\n");
  9101. }
  9102. else
  9103. {
  9104. DEBUG_INFO("fnamePlusPath not exist!\n");
  9105. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9106. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9107. goto end;
  9108. }
  9109. if(strchr(locationstr,'@')==NULL)
  9110. {
  9111. sscanf(locationstr,
  9112. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9113. protocol, host, &port, path);
  9114. strcpy(user,"anonymous");
  9115. strcpy(password,"");
  9116. }
  9117. else
  9118. {
  9119. //DEBUG_INFO("pch=%s\n", pch);
  9120. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9121. protocol, user, password, host, &port, path);
  9122. }
  9123. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9124. {
  9125. DEBUG_INFO("protocol is not ftp/http ! \n");
  9126. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9127. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9128. goto end;
  9129. }
  9130. if(strncmp(locationstr,"http", 4) == 0)
  9131. {
  9132. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9133. sprintf(ftppath,"/%s", path);
  9134. do
  9135. {
  9136. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9137. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9138. sleep(3);
  9139. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9140. if(!isSuccess)
  9141. {
  9142. DEBUG_INFO("Diagnostics fail.\n");
  9143. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9144. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9145. sleep(retryIntervalInt);
  9146. }
  9147. else
  9148. {
  9149. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9150. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9151. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9152. }
  9153. retriesInt--;
  9154. }while((isSuccess == 0)&&(retriesInt >= 0));
  9155. }
  9156. else
  9157. {
  9158. sscanf(host,"%[^/]%s",host1, path1);
  9159. if(strlen(path) > 0)
  9160. sprintf(ftppath,"/%s", path);
  9161. else
  9162. sprintf(ftppath,"/%s", path1);
  9163. int ftppathlen=strlen(ftppath);
  9164. int i=1;
  9165. char filenametemp[50];
  9166. while(i < ftppathlen)
  9167. {
  9168. int len=ftppathlen-i;
  9169. if(ftppath[len]== 47) // '/' ascll code: 47
  9170. {
  9171. DEBUG_INFO("find '/' all right\n");
  9172. break;
  9173. }
  9174. i=i+1;
  9175. }
  9176. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9177. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9178. filenametemp[i+1] = 0;
  9179. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9180. if(port == 0)
  9181. port = 21;
  9182. do
  9183. {
  9184. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9185. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9186. sleep(3);
  9187. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9188. if(!isSuccess)
  9189. {
  9190. DEBUG_INFO("Diagnostics fail.\n");
  9191. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9192. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9193. sleep(retryIntervalInt);
  9194. }
  9195. else
  9196. {
  9197. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9198. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9199. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9200. }
  9201. retriesInt--;
  9202. }while((!isSuccess)&&(retriesInt >= 0));
  9203. }
  9204. end:
  9205. system("rm -f /mnt/*");
  9206. sleep(5);
  9207. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9208. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9209. interLock.isGetDiagnosticGoing = 0;
  9210. pthread_exit(NULL);
  9211. }
  9212. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9213. {
  9214. mtrace();
  9215. int result = FAIL;
  9216. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9217. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9218. {
  9219. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9220. locallistVersion = -1;
  9221. }
  9222. else
  9223. {
  9224. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9225. OCPP_getListVerion();
  9226. }
  9227. //from db.OCPP_getListVerion
  9228. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9229. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9230. sendGetLocalListVersionConfirmation(uuid,"");
  9231. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9232. return result;
  9233. }
  9234. int handleRemoteStartRequest(char *uuid, char *payload)
  9235. {
  9236. mtrace();
  9237. int result = FAIL;
  9238. int connectorIdInt=-1;
  9239. int tempIndex = 0;
  9240. int connectorIdIsNULL, chargingProfileIsNULL;
  9241. char comfirmstr[20]={0};
  9242. char cmdBuf[512];
  9243. json_object *RemoteStartTransaction;
  9244. FILE *fp;
  9245. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9246. if(server_pending == TRUE)
  9247. {
  9248. return 0;
  9249. }
  9250. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9251. RemoteStartTransaction = json_tokener_parse(payload);
  9252. if(!is_error(RemoteStartTransaction))
  9253. {
  9254. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9255. {
  9256. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9257. }
  9258. else
  9259. {
  9260. connectorIdIsNULL = TRUE;
  9261. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9262. {
  9263. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9264. {
  9265. connectorIdIsNULL = FALSE;
  9266. connectorIdInt = (gun_index+1);
  9267. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9268. break;
  9269. }
  9270. }
  9271. }
  9272. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9273. {
  9274. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9275. // Required data
  9276. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9277. // Optional data
  9278. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9279. {
  9280. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9281. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9282. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9283. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9284. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9285. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9286. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9287. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9288. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9289. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9290. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9291. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9292. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9293. {
  9294. 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")));
  9295. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9296. 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"));
  9297. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9298. 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"));
  9299. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9300. 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")));
  9301. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9302. {
  9303. 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++)
  9304. {
  9305. 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"));
  9306. 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"));
  9307. 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)
  9308. 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"));
  9309. }
  9310. }
  9311. }
  9312. }
  9313. else
  9314. {
  9315. chargingProfileIsNULL = TRUE;
  9316. }
  9317. }
  9318. }
  9319. else
  9320. {
  9321. connectorIdIsNULL = TRUE;
  9322. }
  9323. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9324. {
  9325. DEBUG_WARN("Connector id is NULL\n.");
  9326. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9327. goto end;
  9328. }
  9329. /*
  9330. enum _SYSTEM_STATUS
  9331. {
  9332. S_BOOTING = 0,
  9333. S_IDLE, = 1
  9334. S_AUTHORIZING, = 2
  9335. S_REASSIGN_CHECK, = 3
  9336. S_REASSIGN, = 4
  9337. S_PRECHARGE, = 5
  9338. S_PREPARING_FOR_EV, = 6
  9339. S_PREPARING_FOR_EVSE, = 7
  9340. S_CHARGING, = 8
  9341. S_TERMINATING, = 9
  9342. S_COMPLETE, = 10
  9343. S_ALARM, = 11
  9344. S_FAULT = 12
  9345. }
  9346. */
  9347. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9348. {
  9349. //check Transaction active
  9350. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9351. {
  9352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9353. {
  9354. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9355. }
  9356. else
  9357. {
  9358. tempIndex = connectorIdInt -1;
  9359. }
  9360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9361. {
  9362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9363. {
  9364. 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))
  9365. {
  9366. //Reserved
  9367. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9368. }
  9369. 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))
  9370. {
  9371. //Reserved
  9372. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9373. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9374. goto end;
  9375. }
  9376. else
  9377. {
  9378. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9379. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9380. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9381. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9382. {
  9383. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9385. goto end;
  9386. }
  9387. }//END FOR ELSE
  9388. }
  9389. }// END FOR CHAdeMO_QUANTITY
  9390. }
  9391. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9392. {
  9393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9394. {
  9395. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9396. }
  9397. else
  9398. {
  9399. tempIndex = connectorIdInt -1;
  9400. }
  9401. for (int index = 0; index < CCS_QUANTITY; index++)
  9402. {
  9403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9404. {
  9405. 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))
  9406. {
  9407. //Reserved
  9408. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9409. }
  9410. 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))
  9411. {
  9412. //Reserved
  9413. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9415. goto end;
  9416. }
  9417. else
  9418. {
  9419. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9420. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9421. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9422. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9423. {
  9424. DEBUG_WARN("CCS connector not allow start\n.");
  9425. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9426. goto end;
  9427. }
  9428. }// END FOR ELSE
  9429. }
  9430. }// END FOR CCS_QUANTITY
  9431. }
  9432. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9433. {
  9434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9435. {
  9436. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9437. }
  9438. else
  9439. {
  9440. tempIndex = connectorIdInt -1;
  9441. }
  9442. for (int index = 0; index < GB_QUANTITY; index++)
  9443. {
  9444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9445. {
  9446. 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))
  9447. {
  9448. //Reserved
  9449. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9450. }
  9451. 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))
  9452. {
  9453. //Reserved
  9454. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9456. goto end;
  9457. }
  9458. else
  9459. {
  9460. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9461. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9462. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9463. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9464. {
  9465. DEBUG_WARN("GB connector not allow start\n.");
  9466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9467. goto end;
  9468. }
  9469. }// END FOR ELSE
  9470. }
  9471. } // END FOR GB_QUANTITY
  9472. }
  9473. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9474. {
  9475. tempIndex = connectorIdInt -1;
  9476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9477. {
  9478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9479. {
  9480. 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))
  9481. {
  9482. //Reserved
  9483. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9484. }
  9485. 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))
  9486. {
  9487. //Reserved
  9488. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9490. goto end;
  9491. }
  9492. else
  9493. {
  9494. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9495. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9496. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9497. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9498. {
  9499. DEBUG_WARN("GB connector not allow start\n.");
  9500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9501. goto end;
  9502. }
  9503. }// END FOR ELSE
  9504. }
  9505. } // END FOR GB_QUANTITY
  9506. }
  9507. else
  9508. {
  9509. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9510. {
  9511. tempIndex = 2;
  9512. }
  9513. else
  9514. {
  9515. tempIndex = connectorIdInt -1;
  9516. }
  9517. for (int index = 0; index < AC_QUANTITY; index++)
  9518. {
  9519. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9520. {
  9521. 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))
  9522. {
  9523. //Reserved
  9524. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9525. }
  9526. 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))
  9527. {
  9528. //Reserved
  9529. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9531. goto end;
  9532. }
  9533. else
  9534. {
  9535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9536. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9537. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9538. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9539. {
  9540. DEBUG_WARN("AC connector not allow start\n.");
  9541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9542. goto end;
  9543. }
  9544. }//END FOR ELSE
  9545. }
  9546. }// END FOR AC_QUANTITY
  9547. }
  9548. if(chargingProfileIsNULL == FALSE)
  9549. {
  9550. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9551. {
  9552. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9553. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9554. //memset idTag
  9555. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9556. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9557. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9559. // Save profile to file
  9560. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9561. system(cmdBuf);
  9562. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9563. fp = fopen(cmdBuf, "w");
  9564. 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));
  9565. fclose(fp);
  9566. }
  9567. else
  9568. {
  9569. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9571. }
  9572. }
  9573. else
  9574. {
  9575. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9577. //memset idTag
  9578. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9579. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9580. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9582. }
  9583. }
  9584. else
  9585. {
  9586. DEBUG_WARN("Connector id over\n.");
  9587. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9588. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9589. }
  9590. end:
  9591. json_object_put(RemoteStartTransaction);
  9592. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9593. {
  9594. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9595. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9596. }
  9597. //OCPP send RemoteStartConfirmation by first.
  9598. sendRemoteStartConfirmation(uuid, comfirmstr);
  9599. return result;
  9600. }
  9601. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9602. {
  9603. mtrace();
  9604. int result = FAIL;
  9605. int match = FALSE;
  9606. int GunNO = 0;
  9607. int tempIndex = 0;
  9608. int transactionIdInt=0;
  9609. int transactionIdIsNULL= TRUE;
  9610. char comfirmstr[20];
  9611. json_object *RemoteStopTransaction;
  9612. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9613. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9614. if(server_pending == TRUE)
  9615. {
  9616. return 0;
  9617. }
  9618. RemoteStopTransaction = json_tokener_parse(payload);
  9619. if(!is_error(RemoteStopTransaction))
  9620. {
  9621. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9622. {
  9623. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9624. transactionIdIsNULL = FALSE;
  9625. }
  9626. }
  9627. json_object_put(RemoteStopTransaction);
  9628. if(transactionIdIsNULL == FALSE)
  9629. {
  9630. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9631. {
  9632. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9633. {
  9634. //check Transaction active
  9635. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9636. {
  9637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9638. {
  9639. tempIndex = ((gun_index==2) ? 1: 0);
  9640. }
  9641. else
  9642. {
  9643. tempIndex = gun_index;
  9644. }
  9645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9646. {
  9647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9648. {
  9649. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9650. {
  9651. match = TRUE;
  9652. GunNO = gun_index;
  9653. }
  9654. }
  9655. }// END FOR CHAdeMO_QUANTITY
  9656. }
  9657. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9658. {
  9659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9660. {
  9661. tempIndex = ((gun_index==2) ? 1: 0);
  9662. }
  9663. else
  9664. {
  9665. tempIndex = gun_index;
  9666. }
  9667. for (int index = 0; index < CCS_QUANTITY; index++)
  9668. {
  9669. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9670. {
  9671. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9672. {
  9673. match = TRUE;
  9674. GunNO = gun_index;
  9675. }
  9676. }
  9677. }// END FOR CCS_QUANTITY
  9678. }
  9679. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9680. {
  9681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9682. {
  9683. tempIndex = ((gun_index==2) ? 1: 0);
  9684. }
  9685. else
  9686. {
  9687. tempIndex = gun_index;
  9688. }
  9689. for (int index = 0; index < GB_QUANTITY; index++)
  9690. {
  9691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9692. {
  9693. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9694. {
  9695. match = TRUE;
  9696. GunNO = gun_index;
  9697. }
  9698. }
  9699. }// END FOR GB_QUANTITY
  9700. }
  9701. else if(gunType[gun_index] == GUN_TYPE_DO)
  9702. {
  9703. tempIndex = gun_index;
  9704. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9705. {
  9706. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9707. {
  9708. 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
  9709. {
  9710. match = TRUE;
  9711. GunNO = gun_index;
  9712. }
  9713. }
  9714. }// END FOR GB_QUANTITY
  9715. }
  9716. else
  9717. {
  9718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9719. {
  9720. tempIndex = 2;
  9721. }
  9722. else
  9723. {
  9724. tempIndex = gun_index;
  9725. }
  9726. for (int index = 0; index < AC_QUANTITY; index++)
  9727. {
  9728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9729. {
  9730. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9731. {
  9732. match = TRUE;
  9733. GunNO = gun_index;
  9734. }
  9735. }
  9736. }// END FOR CHAdeMO_QUANTITY
  9737. } // END FOR AC ELSE
  9738. }// CHECK IF ResponseTransactionId == transactionIdInt
  9739. }//END FOR
  9740. if( match == TRUE)
  9741. {
  9742. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9744. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9745. }
  9746. else
  9747. {
  9748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9749. }
  9750. }
  9751. else
  9752. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9753. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9754. return result;
  9755. }
  9756. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9757. {
  9758. mtrace();
  9759. int result = FAIL;
  9760. int connectorIdInt=0, reservationIdInt=0;
  9761. int tempIndex = 0;
  9762. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9763. char comfirmstr[20]={0};
  9764. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9765. int c = 0;
  9766. char *loc;
  9767. //char *ptr;
  9768. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9769. strcpy(sstrtemp, stringtrimspace(payload));
  9770. //***(1)connectorId ****/
  9771. c=0;
  9772. loc = strstr(sstrtemp, "connectorId");
  9773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9774. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9775. {
  9776. sstr[c] = loc[strlen("connectorId")+2+c];
  9777. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9778. c++;
  9779. }
  9780. sstr[c] = '\0';
  9781. connectorIdInt = atoi(sstr);
  9782. //***(2)expiryDate ****/
  9783. loc = strstr(sstrtemp, "expiryDate");
  9784. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9785. c = 0;
  9786. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9787. {
  9788. sstr[c] = loc[3+strlen("expiryDate")+c];
  9789. c++;
  9790. }
  9791. sstr[c] = '\0';
  9792. strcpy(expiryDatestr, sstr);
  9793. //***(3)idTag ****/
  9794. loc = strstr(sstrtemp, "idTag");
  9795. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9796. c = 0;
  9797. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9798. {
  9799. sstr[c] = loc[3+strlen("idTag")+c];
  9800. c++;
  9801. }
  9802. sstr[c] = '\0';
  9803. strcpy(idTagstr, sstr);
  9804. //***(4)parentIdTag ****/
  9805. loc = strstr(sstrtemp, "parentIdTag");
  9806. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9807. c = 0;
  9808. if(loc == NULL)
  9809. {
  9810. strcpy(parentIdTagstr, "");
  9811. }
  9812. else
  9813. {
  9814. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9815. {
  9816. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9817. c++;
  9818. }
  9819. sstr[c] = '\0';
  9820. strcpy(parentIdTagstr, sstr);
  9821. }
  9822. //***(5)reservationId ****/
  9823. c=0;
  9824. loc = strstr(sstrtemp, "reservationId");
  9825. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9826. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9827. {
  9828. sstr[c] = loc[strlen("reservationId")+2+c];
  9829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9830. c++;
  9831. }
  9832. sstr[c] = '\0';
  9833. reservationIdInt = atoi(sstr);
  9834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9835. /*
  9836. enum SYSTEM_STATUS
  9837. {
  9838. SYS_MODE_BOOTING = 0,
  9839. SYS_MODE_IDLE = 1,
  9840. SYS_MODE_AUTHORIZING = 2,
  9841. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9842. SYS_MODE_REASSIGN = 4,
  9843. SYS_MODE_PREPARING = 5,
  9844. SYS_MODE_PREPARE_FOR_EV = 6,
  9845. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9846. SYS_MODE_CHARGING = 8,
  9847. SYS_MODE_TERMINATING = 9,
  9848. SYS_MODE_COMPLETE = 10,
  9849. SYS_MODE_ALARM = 11,
  9850. SYS_MODE_FAULT = 12,
  9851. SYS_MODE_RESERVATION = 13,
  9852. SYS_MODE_BOOKING = 14,
  9853. SYS_MODE_MAINTAIN = 15,
  9854. SYS_MODE_DEBUG = 16,
  9855. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9856. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9857. SYS_MODE_UPDATE = 19
  9858. };
  9859. */
  9860. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9861. {
  9862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9863. goto end;
  9864. }
  9865. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9866. {
  9867. //check Transaction active
  9868. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9869. {
  9870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9871. {
  9872. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9873. }
  9874. else
  9875. {
  9876. tempIndex = connectorIdInt -1;
  9877. }
  9878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9879. {
  9880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9881. {
  9882. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9883. {
  9884. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9885. {
  9886. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9887. {
  9888. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9890. }
  9891. 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'))
  9892. {
  9893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9894. }
  9895. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9896. {
  9897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9898. }
  9899. else
  9900. {
  9901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9902. }
  9903. }
  9904. 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
  9905. {
  9906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9907. }
  9908. }
  9909. else
  9910. {
  9911. //replace reservation
  9912. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9914. }
  9915. }
  9916. } // END FOR CHAdeMO_QUANTITY
  9917. }
  9918. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9919. {
  9920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9921. {
  9922. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9923. }
  9924. else
  9925. {
  9926. tempIndex = connectorIdInt -1;
  9927. }
  9928. for (int index = 0; index < CCS_QUANTITY; index++)
  9929. {
  9930. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9931. {
  9932. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9933. {
  9934. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9935. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9936. {
  9937. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9938. {
  9939. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9941. }
  9942. 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'))
  9943. {
  9944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9945. }
  9946. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9947. {
  9948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9949. }
  9950. else
  9951. {
  9952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9953. }
  9954. }
  9955. 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
  9956. {
  9957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9958. }
  9959. }
  9960. else
  9961. {
  9962. //replace reservation
  9963. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9965. }
  9966. }
  9967. } // END FOR CCS_QUANTITY
  9968. }
  9969. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9970. {
  9971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9972. {
  9973. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9974. }
  9975. else
  9976. {
  9977. tempIndex = connectorIdInt -1;
  9978. }
  9979. for (int index = 0; index < GB_QUANTITY; index++)
  9980. {
  9981. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9982. {
  9983. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9984. {
  9985. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9986. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9987. {
  9988. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9989. {
  9990. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9992. }
  9993. 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'))
  9994. {
  9995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9996. }
  9997. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9998. {
  9999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10000. }
  10001. else
  10002. {
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10004. }
  10005. }
  10006. 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
  10007. {
  10008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10009. }
  10010. }
  10011. else
  10012. {
  10013. //replace reservation
  10014. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10016. }
  10017. }
  10018. }// END FOR GB_QUANTITY
  10019. }
  10020. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10021. {
  10022. tempIndex = connectorIdInt -1;
  10023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10024. {
  10025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10026. {
  10027. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10028. {
  10029. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10030. 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
  10031. {
  10032. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10033. {
  10034. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10036. }
  10037. 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'))
  10038. {
  10039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10040. }
  10041. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10042. {
  10043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10044. }
  10045. else
  10046. {
  10047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10048. }
  10049. }
  10050. 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
  10051. {
  10052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10053. }
  10054. }
  10055. else
  10056. {
  10057. //replace reservation
  10058. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10060. }
  10061. }
  10062. }// END FOR GB_QUANTITY
  10063. }
  10064. else
  10065. {
  10066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10067. {
  10068. tempIndex = 2;
  10069. }
  10070. else
  10071. {
  10072. tempIndex = (connectorIdInt -1);
  10073. }
  10074. for (int index = 0; index < AC_QUANTITY; index++)
  10075. {
  10076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10077. {
  10078. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10079. {
  10080. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10081. {
  10082. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10083. {
  10084. 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))
  10085. {
  10086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10087. }
  10088. else
  10089. {
  10090. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10092. }
  10093. }
  10094. 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'))
  10095. {
  10096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10097. }
  10098. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10099. {
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10101. }
  10102. else
  10103. {
  10104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10105. }
  10106. }
  10107. 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
  10108. {
  10109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10110. }
  10111. }
  10112. else
  10113. {
  10114. //replace reservation
  10115. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10117. }
  10118. }
  10119. } // END FOR AC_QUANTITY
  10120. }
  10121. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10122. }
  10123. else if(connectorIdInt == 0)
  10124. {
  10125. //check Transaction active
  10126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10127. {
  10128. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10129. {
  10130. 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'))
  10131. {
  10132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10133. goto end;
  10134. }
  10135. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10136. {
  10137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10138. goto end;
  10139. }
  10140. 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
  10141. {
  10142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10143. goto end;
  10144. }
  10145. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10146. {
  10147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10148. goto end;
  10149. }
  10150. }
  10151. }// END FOR CHAdeMO_QUANTITY
  10152. for (int index = 0; index < CCS_QUANTITY; index++)
  10153. {
  10154. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10155. {
  10156. 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'))
  10157. {
  10158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10159. goto end;
  10160. }
  10161. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10162. {
  10163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10164. goto end;
  10165. }
  10166. 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
  10167. {
  10168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10169. goto end;
  10170. }
  10171. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10172. {
  10173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10174. goto end;
  10175. }
  10176. }
  10177. } // END FOR CCS_QUANTITY
  10178. for (int index = 0; index < GB_QUANTITY; index++)
  10179. {
  10180. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10181. {
  10182. 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'))
  10183. {
  10184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10185. goto end;
  10186. }
  10187. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10188. {
  10189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10190. goto end;
  10191. }
  10192. 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
  10193. {
  10194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10195. goto end;
  10196. }
  10197. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10198. {
  10199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10200. goto end;
  10201. }
  10202. }
  10203. } // END FOR GB_QUANTITY
  10204. for (int index = 0; index < AC_QUANTITY; index++)
  10205. {
  10206. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10207. {
  10208. 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'))
  10209. {
  10210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10211. goto end;
  10212. }
  10213. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10214. {
  10215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10216. goto end;
  10217. }
  10218. 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
  10219. {
  10220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10221. goto end;
  10222. }
  10223. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10224. {
  10225. 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))
  10226. {
  10227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10228. goto end;
  10229. }
  10230. }
  10231. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10232. {
  10233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10234. goto end;
  10235. }
  10236. }
  10237. }// END FOR AC_QUANTITY
  10238. //The connectorId is 0
  10239. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10241. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10242. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10243. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10244. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10245. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10246. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10247. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10248. result = TRUE;
  10249. return result;
  10250. }
  10251. else
  10252. {
  10253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10254. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10255. }
  10256. if(strcmp(comfirmstr,"Accepted") == 0)
  10257. {
  10258. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10259. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10260. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10261. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10262. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10263. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10264. result = TRUE;
  10265. return result;
  10266. }
  10267. end:
  10268. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10269. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10270. return result;
  10271. }
  10272. int handleResetRequest(char *uuid, char *payload)
  10273. {
  10274. mtrace();
  10275. int result = FAIL;
  10276. char sstr[10]={0},sstrtemp[30]={ 0 };
  10277. char typestr[10]={0};
  10278. char comfirmstr[20]={0};
  10279. int c = 0;
  10280. char *loc;
  10281. DEBUG_INFO("handleResetRequest...\n");
  10282. strcpy(sstrtemp, stringtrimspace(payload));
  10283. loc = strstr(sstrtemp, "type");
  10284. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10285. c = 0;
  10286. while (loc[3+strlen("type")+c] != '\"')
  10287. {
  10288. sstr[c] = loc[3+strlen("type")+c];
  10289. c++;
  10290. }
  10291. sstr[c] = '\0';
  10292. strcpy(typestr,sstr);
  10293. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10294. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10295. {
  10296. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10297. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10298. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10299. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10300. }
  10301. else
  10302. {
  10303. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10304. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10305. result = PASS;
  10306. }
  10307. sendResetConfirmation(uuid, comfirmstr);
  10308. return result;
  10309. }
  10310. int handleSendLocalListRequest(char *uuid, char *payload)
  10311. {
  10312. mtrace();
  10313. int result = FAIL;
  10314. char comfirmstr[20];
  10315. int checkState_Faulted = FALSE;
  10316. json_object *SendLocalList;
  10317. DEBUG_INFO("handleSendLocalListRequest...\n");
  10318. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10319. {
  10320. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10321. goto end;
  10322. }
  10323. //check Charge Point state
  10324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10325. {
  10326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10327. {
  10328. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10329. }
  10330. }
  10331. for (int index = 0; index < CCS_QUANTITY; index++)
  10332. {
  10333. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10334. {
  10335. checkState_Faulted = TRUE; //OCPP Status
  10336. }
  10337. }
  10338. for (int index = 0; index < GB_QUANTITY; index++)
  10339. {
  10340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10341. {
  10342. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10343. }
  10344. }
  10345. //check Charge Point state
  10346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10347. {
  10348. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10349. {
  10350. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10351. }
  10352. }
  10353. //check Charge Point state
  10354. for (int index = 0; index < AC_QUANTITY; index++)
  10355. {
  10356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10357. {
  10358. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10359. }
  10360. }
  10361. if(checkState_Faulted == TRUE)
  10362. {
  10363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10364. goto end;
  10365. }
  10366. // Parsing payload
  10367. SendLocalList = json_tokener_parse(payload);
  10368. if(!is_error(SendLocalList))
  10369. {
  10370. // Required data
  10371. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10372. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10373. // Optional data
  10374. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10375. {
  10376. //Check UpdateType
  10377. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10378. {
  10379. //Local list full update
  10380. DEBUG_INFO("Local list full update.\n");
  10381. OCPP_getListVerion();
  10382. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10383. {
  10384. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10385. goto end;
  10386. }
  10387. OCPP_cleanLocalList();
  10388. }
  10389. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10390. {
  10391. //Local list different update
  10392. DEBUG_INFO("Local list different update.\n");
  10393. OCPP_getListVerion();
  10394. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10395. {
  10396. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10397. goto end;
  10398. }
  10399. }
  10400. else
  10401. {
  10402. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10403. goto end;
  10404. }
  10405. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10406. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10407. {
  10408. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10409. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10410. {
  10411. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10412. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10413. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10414. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10415. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10416. }
  10417. // Add to db
  10418. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10419. {
  10420. //Local list full update
  10421. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10422. idx,
  10423. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10424. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10425. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10426. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10427. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10428. // update list
  10429. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10430. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10431. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10432. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10433. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10434. }
  10435. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10436. {
  10437. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10438. idx,
  10439. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10440. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10441. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10442. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10443. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10444. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10445. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10446. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10447. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10448. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10449. }
  10450. }
  10451. }
  10452. else
  10453. {
  10454. //Check UpdateType
  10455. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10456. {
  10457. //Local list full update
  10458. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10459. OCPP_cleanLocalList();
  10460. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10461. goto end;
  10462. }
  10463. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10464. {
  10465. //Local list different update
  10466. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10467. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10468. goto end;
  10469. }
  10470. }
  10471. result = PASS;
  10472. }
  10473. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10474. end:
  10475. json_object_put(SendLocalList);
  10476. sendSendLocalListConfirmation(uuid, comfirmstr);
  10477. return result;
  10478. }
  10479. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10480. {
  10481. mtrace();
  10482. int result = FAIL;
  10483. struct StructSetChargingProfile SetProfileReq = {0};
  10484. int tempchargingProfileIdInt;
  10485. int chargingSchedulePeriodCount = 0;
  10486. char comfirmstr[20]={0};
  10487. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10488. char rmFileCmd[128]={0};
  10489. int profileQuantity = 0;
  10490. json_object *SetChargingProfile;
  10491. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10492. SetChargingProfile = json_tokener_parse(payload);
  10493. if(!is_error(SetChargingProfile))
  10494. {
  10495. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10496. {
  10497. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10498. }
  10499. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10500. {
  10501. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10502. {
  10503. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10504. }
  10505. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10506. {
  10507. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10508. }
  10509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10510. {
  10511. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10512. }
  10513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10514. {
  10515. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10516. }
  10517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10518. {
  10519. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10520. }
  10521. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10522. {
  10523. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10524. }
  10525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10526. {
  10527. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10528. }
  10529. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10530. {
  10531. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10532. }
  10533. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10534. {
  10535. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10536. {
  10537. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10538. }
  10539. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10540. {
  10541. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10542. }
  10543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10544. {
  10545. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10546. }
  10547. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10548. {
  10549. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10550. }
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10552. {
  10553. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10554. if(chargingSchedulePeriodCount <= 10)
  10555. {
  10556. 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++)
  10557. {
  10558. 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)
  10559. {
  10560. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10561. }
  10562. 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)
  10563. {
  10564. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10565. }
  10566. 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)
  10567. {
  10568. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10569. }
  10570. }
  10571. }
  10572. }
  10573. }
  10574. }
  10575. }
  10576. // Profile periods quantity check
  10577. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10578. {
  10579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10580. goto end;
  10581. }
  10582. // Profile purpose info check
  10583. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10584. {
  10585. FILE *fp;
  10586. char dataLine[4096]={0};
  10587. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10588. if(SetProfileReq.ConnectorId != 0)
  10589. {
  10590. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10591. goto end;
  10592. }
  10593. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10594. if (!fp)
  10595. {
  10596. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10597. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10598. }
  10599. else
  10600. {
  10601. while(fscanf(fp, "%s", dataLine) != EOF)
  10602. {
  10603. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10604. {
  10605. profileQuantity += 1;
  10606. }
  10607. }
  10608. }
  10609. fclose(fp);
  10610. }
  10611. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10612. {
  10613. FILE *fp;
  10614. char dataLine[4096]={0};
  10615. char filename[128]={0};
  10616. int tmpProfileQuantity;
  10617. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10618. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10619. {
  10620. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10621. goto end;
  10622. }
  10623. if(SetProfileReq.ConnectorId == 0)
  10624. {
  10625. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10626. {
  10627. tmpProfileQuantity = 0;
  10628. memset(filename, 0, ARRAY_SIZE(filename));
  10629. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10630. fp = fopen(filename, "r");
  10631. if (!fp)
  10632. {
  10633. DEBUG_INFO("%s does not create.\n", filename);
  10634. fp = fopen(filename, "w+");
  10635. }
  10636. else
  10637. {
  10638. while(fscanf(fp, "%s", dataLine) != EOF)
  10639. {
  10640. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10641. {
  10642. tmpProfileQuantity += 1;
  10643. }
  10644. }
  10645. }
  10646. fclose(fp);
  10647. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10648. }
  10649. }
  10650. else
  10651. {
  10652. memset(filename, 0, ARRAY_SIZE(filename));
  10653. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10654. fp = fopen(filename, "r");
  10655. if (!fp)
  10656. {
  10657. DEBUG_INFO("%s does not create.\n", filename);
  10658. fp = fopen(filename, "w+");
  10659. }
  10660. else
  10661. {
  10662. while(fscanf(fp, "%s", dataLine) != EOF)
  10663. {
  10664. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10665. {
  10666. profileQuantity += 1;
  10667. }
  10668. }
  10669. }
  10670. fclose(fp);
  10671. }
  10672. }
  10673. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10674. {
  10675. int isMatchTransactiodId= FALSE;
  10676. FILE *fp;
  10677. char dataLine[4096]={0};
  10678. char filename[128]={0};
  10679. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10680. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10681. if(SetProfileReq.ConnectorId == 0)
  10682. {
  10683. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10684. goto end;
  10685. }
  10686. int tempIndex = 0;
  10687. //check Transaction active
  10688. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10689. {
  10690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10691. {
  10692. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10693. }
  10694. else
  10695. {
  10696. tempIndex = SetProfileReq.ConnectorId -1;
  10697. }
  10698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10699. {
  10700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10701. {
  10702. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10703. {
  10704. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10705. {
  10706. isMatchTransactiodId = TRUE;
  10707. break;
  10708. }
  10709. }
  10710. }
  10711. }
  10712. }
  10713. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10714. {
  10715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10716. {
  10717. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10718. }
  10719. else
  10720. {
  10721. tempIndex = SetProfileReq.ConnectorId -1;
  10722. }
  10723. for (int index = 0; index < CCS_QUANTITY; index++)
  10724. {
  10725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10726. {
  10727. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  10728. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10729. {
  10730. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10731. {
  10732. isMatchTransactiodId = TRUE;
  10733. break;
  10734. }
  10735. }
  10736. }
  10737. }
  10738. }
  10739. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10740. {
  10741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10742. {
  10743. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10744. }
  10745. else
  10746. {
  10747. tempIndex = SetProfileReq.ConnectorId -1;
  10748. }
  10749. for (int index = 0; index < GB_QUANTITY; index++)
  10750. {
  10751. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10752. {
  10753. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10754. {
  10755. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10756. {
  10757. isMatchTransactiodId = TRUE;
  10758. break;
  10759. }
  10760. }
  10761. }
  10762. }
  10763. }
  10764. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10765. {
  10766. tempIndex = SetProfileReq.ConnectorId -1;
  10767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10768. {
  10769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10770. {
  10771. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  10772. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10773. {
  10774. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10775. {
  10776. isMatchTransactiodId = TRUE;
  10777. break;
  10778. }
  10779. }
  10780. }
  10781. }
  10782. }
  10783. else
  10784. {
  10785. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10786. {
  10787. tempIndex = 2;
  10788. }
  10789. else
  10790. {
  10791. tempIndex = (SetProfileReq.ConnectorId -1);
  10792. }
  10793. for (int index = 0; index < AC_QUANTITY; index++)
  10794. {
  10795. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10796. {
  10797. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10798. {
  10799. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10800. {
  10801. isMatchTransactiodId = TRUE;
  10802. break;
  10803. }
  10804. }
  10805. }
  10806. }
  10807. }
  10808. //check Transaction active
  10809. if(isMatchTransactiodId == FALSE)
  10810. {
  10811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10812. goto end;
  10813. }
  10814. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10815. {
  10816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10817. goto end;
  10818. }
  10819. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10820. fp = fopen(filename, "r");
  10821. if (!fp)
  10822. {
  10823. DEBUG_INFO("%s does not create.\n", filename);
  10824. fp = fopen(filename, "w+");
  10825. }
  10826. else
  10827. {
  10828. //Check Charging Profile Count
  10829. while(fscanf(fp, "%s", dataLine) != EOF)
  10830. {
  10831. //DEBUG_INFO("word=%s\n",word);
  10832. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10833. {
  10834. profileQuantity += 1;
  10835. }
  10836. }
  10837. }
  10838. fclose(fp);
  10839. }
  10840. // Check ChargeProfileMaxStackLevel
  10841. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  10842. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10843. {
  10844. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10845. goto end;
  10846. }
  10847. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10848. {
  10849. FILE *fp;
  10850. char dataLine[4096]={0};
  10851. char fnametemp[128]={0};
  10852. int tmpProfileQuantity;
  10853. //Check ChargePointMaxProfile.json exit
  10854. profileQuantity = 0;
  10855. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10856. {
  10857. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10858. //Check Charging Profile Count
  10859. tmpProfileQuantity = 0;
  10860. while(fscanf(fp, "%s", dataLine) != EOF)
  10861. {
  10862. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10863. {
  10864. profileQuantity += 1;
  10865. tmpProfileQuantity += 1;
  10866. }
  10867. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10868. }
  10869. fclose(fp);
  10870. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  10871. }
  10872. //Check TxDefaultProfile_%d.json
  10873. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10874. {
  10875. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10876. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10877. if((access(fnametemp,F_OK))!=-1)
  10878. {
  10879. fp = fopen(fnametemp, "r");
  10880. //Check Charging Profile Count
  10881. tmpProfileQuantity = 0;
  10882. while(fscanf(fp, "%s", dataLine) != EOF)
  10883. {
  10884. //DEBUG_INFO("word=%s\n",word);
  10885. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10886. {
  10887. profileQuantity += 1;
  10888. tmpProfileQuantity += 1;
  10889. }
  10890. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10891. }
  10892. fclose(fp);
  10893. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10894. }
  10895. }
  10896. //Check TxProfile_%d.json
  10897. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10898. {
  10899. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10900. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  10901. if((access(fnametemp,F_OK))!=-1)
  10902. {
  10903. fp = fopen(fnametemp, "r");
  10904. //Check Charging Profile Count
  10905. tmpProfileQuantity = 0;
  10906. while(fscanf(fp, "%s", dataLine) != EOF)
  10907. {
  10908. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10909. {
  10910. profileQuantity += 1;
  10911. tmpProfileQuantity += 1;
  10912. }
  10913. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10914. }
  10915. fclose(fp);
  10916. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10917. }
  10918. }
  10919. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  10920. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10921. {
  10922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10923. goto end;
  10924. }
  10925. }
  10926. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10927. //**********************************Write to File********************************************************/
  10928. {
  10929. FILE *infile;
  10930. FILE *outfile;
  10931. char dataLine[4096]={0};
  10932. char filename[128]={0};
  10933. int chkChar=0;
  10934. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  10935. {
  10936. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10937. {
  10938. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  10939. }
  10940. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10941. {
  10942. if(SetProfileReq.ConnectorId==0)
  10943. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10944. else
  10945. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10946. }
  10947. else
  10948. {
  10949. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10950. }
  10951. infile = fopen (filename, "r");
  10952. outfile = fopen (tempfile, "w");
  10953. chkChar = fgetc(infile);
  10954. rewind(infile);
  10955. if(chkChar == EOF)
  10956. {
  10957. // Profile is empty
  10958. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10959. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10960. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10961. fclose(infile);
  10962. fclose(outfile);
  10963. sprintf(rmFileCmd,"rm -f %s",filename);
  10964. system(rmFileCmd);
  10965. rename(tempfile, filename);
  10966. }
  10967. else
  10968. {
  10969. // Profile is not empty
  10970. int ChargingProfileAdded = FALSE;
  10971. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  10972. {
  10973. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  10974. json_object *tmpChargingProfile;
  10975. tmpChargingProfile = json_tokener_parse(dataLine);
  10976. if(!is_error(SetChargingProfile))
  10977. {
  10978. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10979. {
  10980. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10981. {
  10982. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10983. }
  10984. }
  10985. }
  10986. json_object_put(tmpChargingProfile);
  10987. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  10988. {
  10989. if(ChargingProfileAdded == FALSE)
  10990. {
  10991. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10992. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10993. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10994. ChargingProfileAdded = TRUE;
  10995. }
  10996. }
  10997. else
  10998. {
  10999. fprintf(outfile,"%s\n",dataLine);
  11000. if(ChargingProfileAdded == FALSE)
  11001. {
  11002. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11003. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11004. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11005. ChargingProfileAdded = TRUE;
  11006. }
  11007. }
  11008. } // end of while loop
  11009. fclose(infile);
  11010. fclose(outfile);
  11011. sprintf(rmFileCmd,"rm -f %s",filename);
  11012. system(rmFileCmd);
  11013. rename(tempfile, filename);
  11014. }
  11015. }
  11016. sleep(1);
  11017. result = TRUE;
  11018. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11019. }
  11020. end:
  11021. json_object_put(SetChargingProfile);
  11022. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11023. {
  11024. if(SetProfileReq.ConnectorId == 0)
  11025. {
  11026. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11027. {
  11028. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11029. }
  11030. }
  11031. else
  11032. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11033. }
  11034. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11035. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11036. return result;
  11037. }
  11038. int handleTriggerMessageRequest(char *uuid, char *payload)
  11039. {
  11040. mtrace();
  11041. int result = FAIL;
  11042. int connectorIdIsNULL = FALSE;
  11043. int connectorIdInt =0;
  11044. char sstr[40]={0},sstrtemp[100]={ 0 };
  11045. char requestedMessagestr[40]={0};
  11046. char comfirmstr[20]={0};
  11047. int c = 0;
  11048. char *loc;
  11049. DEBUG_INFO("handleTriggerMessageRequest\n");
  11050. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11051. strcpy(sstrtemp, stringtrimspace(payload));
  11052. c = 0;
  11053. loc = strstr(sstrtemp, "requestedMessage");
  11054. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11055. {
  11056. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11057. c++;
  11058. }
  11059. sstr[c] = '\0';
  11060. strcpy(requestedMessagestr, sstr);
  11061. c = 0;
  11062. loc = strstr(sstrtemp, "connectorId");
  11063. if(loc == NULL)
  11064. {
  11065. connectorIdIsNULL = TRUE;
  11066. }
  11067. else
  11068. {
  11069. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11070. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11071. {
  11072. sstr[c] = loc[strlen("connectorId")+2+c];
  11073. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11074. c++;
  11075. }
  11076. sstr[c] = '\0';
  11077. connectorIdInt = atoi(sstr);
  11078. }
  11079. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11080. {
  11081. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11082. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11083. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11084. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11085. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11086. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11087. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11088. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11089. {
  11090. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11091. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11092. return TRUE;
  11093. }
  11094. else
  11095. {
  11096. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11097. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11098. }
  11099. }
  11100. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11101. {
  11102. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11103. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11104. return TRUE;
  11105. }
  11106. //==========================
  11107. // Trigger message
  11108. //==========================
  11109. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11110. {
  11111. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11112. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11113. {
  11114. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11115. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11116. }
  11117. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11118. }
  11119. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11120. {
  11121. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11122. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11123. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11124. }
  11125. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11126. {
  11127. //sendBootNotificationRequest();
  11128. server_sign = FALSE;
  11129. }
  11130. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11131. {
  11132. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11133. }
  11134. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11135. {
  11136. if(connectorIdIsNULL == FALSE)
  11137. {
  11138. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11139. {
  11140. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11141. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11142. }
  11143. }
  11144. else
  11145. {
  11146. for(int idx=0;idx< gunTotalNumber;idx++)
  11147. {
  11148. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11149. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11150. }
  11151. }
  11152. }
  11153. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11154. {
  11155. if(connectorIdIsNULL == FALSE)
  11156. {
  11157. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11158. {
  11159. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11160. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11161. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11162. }
  11163. }
  11164. else
  11165. {
  11166. for(int idx=0;idx< gunTotalNumber;idx++)
  11167. {
  11168. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11169. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11170. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11171. }
  11172. }
  11173. }
  11174. return result;
  11175. }
  11176. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11177. {
  11178. mtrace();
  11179. int result = FAIL;
  11180. int connectorIdInt =0;
  11181. char comfirmstr[20]={0};
  11182. int tempIndex = 0;
  11183. json_object *UnlockConnector;
  11184. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11185. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11186. UnlockConnector = json_tokener_parse(payload);
  11187. if(!is_error(UnlockConnector))
  11188. {
  11189. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11190. {
  11191. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11192. }
  11193. }
  11194. json_object_put(UnlockConnector);
  11195. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11196. if(gunTotalNumber == 0)
  11197. {
  11198. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11199. goto end;
  11200. }
  11201. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11202. {
  11203. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11204. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11205. goto end;
  11206. }
  11207. else
  11208. {
  11209. //check Transaction active
  11210. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11211. {
  11212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11213. {
  11214. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11215. }
  11216. else
  11217. {
  11218. tempIndex = connectorIdInt -1;
  11219. }
  11220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11221. {
  11222. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11223. {
  11224. //stop Transaction
  11225. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11226. }
  11227. }
  11228. }
  11229. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11230. {
  11231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11232. {
  11233. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11234. }
  11235. else
  11236. {
  11237. tempIndex = connectorIdInt -1;
  11238. }
  11239. for (int index = 0; index < CCS_QUANTITY; index++)
  11240. {
  11241. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11242. {
  11243. //stop Transaction
  11244. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11245. }
  11246. }
  11247. }
  11248. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11249. {
  11250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11251. {
  11252. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11253. }
  11254. else
  11255. {
  11256. tempIndex = connectorIdInt -1;
  11257. }
  11258. for (int index = 0; index < GB_QUANTITY; index++)
  11259. {
  11260. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11261. {
  11262. //stop Transaction
  11263. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11264. }
  11265. }
  11266. }
  11267. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11268. {
  11269. tempIndex = connectorIdInt -1;
  11270. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11271. {
  11272. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11273. {
  11274. //stop Transaction
  11275. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11276. }
  11277. }
  11278. }
  11279. else
  11280. {
  11281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11282. {
  11283. tempIndex = 2;
  11284. }
  11285. else
  11286. {
  11287. tempIndex = connectorIdInt-1;
  11288. }
  11289. for (int index = 0; index < AC_QUANTITY; index++)
  11290. {
  11291. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11292. {
  11293. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11294. }
  11295. }
  11296. }
  11297. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11298. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11299. result = TRUE;
  11300. return result;
  11301. }
  11302. end:
  11303. //json_object_put(obj); --- remove temporally
  11304. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11305. return result;
  11306. }
  11307. static char UpdateFirmwarepayloadData[300]={0};
  11308. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11309. {
  11310. mtrace();
  11311. int result = FAIL;
  11312. pthread_t t;
  11313. sendUpdateFirmwareConfirmation(uuid);
  11314. memset(UpdateFirmwarepayloadData, 0, 300);
  11315. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11316. if(!interLock.isUpdateFirmwareGoing)
  11317. {
  11318. interLock.isUpdateFirmwareGoing = 1;
  11319. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11320. sleep(1);
  11321. }
  11322. else
  11323. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11324. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11325. return result;
  11326. }
  11327. void *UpdateFirmwareProcess(void *data)
  11328. {
  11329. pthread_detach(pthread_self());
  11330. mtrace();
  11331. int retriesInt =0, retryIntervalInt=0;
  11332. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11333. int port=0;
  11334. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11335. int isSuccess = 0;
  11336. char ftpbuf[512];
  11337. char temp[100];
  11338. char * pch;
  11339. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11340. json_object *UpdateFirmware;
  11341. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11342. if(!is_error(UpdateFirmware))
  11343. {
  11344. // Required data
  11345. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11346. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11347. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11348. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11349. // Optional data
  11350. if(json_object_object_get(UpdateFirmware, "retries"))
  11351. {
  11352. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11353. }
  11354. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11355. {
  11356. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11357. }
  11358. }
  11359. json_object_put(UpdateFirmware);
  11360. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11361. memset(path, 0, ARRAY_SIZE(path));
  11362. // Wait retrieveData
  11363. if(strlen(retrieveDatestr) > 10)
  11364. {
  11365. do
  11366. {
  11367. sleep(1);
  11368. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11369. }
  11370. // Ready to download
  11371. system("rm -f /mnt/*");
  11372. if(strncmp(locationstr,"http", 4) == 0)
  11373. {
  11374. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11375. sprintf(ftppath,"/%s", path);
  11376. DEBUG_INFO("locationstr: %s\n", locationstr);
  11377. DEBUG_INFO("protocol: %s\n",protocol);
  11378. DEBUG_INFO("host: %s\n",host);
  11379. DEBUG_INFO("path: %s\n",path);
  11380. DEBUG_INFO("ftppath: %s\n",ftppath);
  11381. int ftppathlen=strlen(ftppath);
  11382. int i=1;
  11383. char filenametemp[50];
  11384. while(i < ftppathlen)
  11385. {
  11386. int len=ftppathlen-i;
  11387. if(ftppath[len]== 47) // '/' ascll code: 47
  11388. {
  11389. DEBUG_INFO("compare '/' all right\n");
  11390. break;
  11391. }
  11392. i=i+1;
  11393. }
  11394. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11395. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11396. filenametemp[i+1] = 0;
  11397. do
  11398. {
  11399. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11400. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11401. sleep(1);
  11402. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11403. if(!isSuccess)
  11404. {
  11405. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11406. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11407. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11408. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11409. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11410. }
  11411. else
  11412. {
  11413. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11414. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11415. }
  11416. retriesInt--;
  11417. }while((isSuccess == 0)&&(retriesInt >= 0));
  11418. }
  11419. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11420. {
  11421. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11422. memset(temp, 0, ARRAY_SIZE(temp));
  11423. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11424. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11425. int ftppathlen=strlen(ftpbuf);
  11426. int i=1;
  11427. char filenametemp[50];
  11428. while(i < ftppathlen)
  11429. {
  11430. int len=ftppathlen-i;
  11431. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11432. {
  11433. DEBUG_INFO(" compare '/' all right\n");
  11434. break;
  11435. }
  11436. i=i+1;
  11437. }
  11438. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11439. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11440. filenametemp[i+1] = 0;
  11441. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11442. pch=strchr(temp,'@');
  11443. if(pch==NULL)
  11444. {
  11445. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11446. protocol, host, &port, path);
  11447. strcpy(user,"anonymous");
  11448. strcpy(password,"");
  11449. }
  11450. else
  11451. {
  11452. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11453. protocol, user, password, host, &port, path);
  11454. }
  11455. sscanf(host,"%[^/]%s",host1, path1);
  11456. sprintf(ftppath,"%s", path1);
  11457. //DEBUG_INFO("protocol =%s\n",protocol);
  11458. //DEBUG_INFO("user =%s\n",user);
  11459. //DEBUG_INFO("password =%s\n",password);
  11460. //DEBUG_INFO("host1 =%s\n",host1);
  11461. //DEBUG_INFO("port =%d\n",port);
  11462. //DEBUG_INFO("path1 =%s\n",path1);
  11463. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11464. //ftpFile(host, user, password, port, ftppath, fname);
  11465. //download firmware pthred
  11466. if(port == 0)
  11467. {
  11468. port = 21;
  11469. }
  11470. do
  11471. {
  11472. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11473. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11474. sleep(1);
  11475. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11476. if(!isSuccess)
  11477. {
  11478. //BulldogUtil.sleepMs(interval*1000);
  11479. DEBUG_INFO("Update firmware request and download file fail.\n");
  11480. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11481. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11482. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11483. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11484. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11485. }
  11486. else
  11487. {
  11488. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11489. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11490. }
  11491. retriesInt--;
  11492. }while((!isSuccess)&&(retriesInt >= 0));
  11493. }
  11494. else
  11495. {
  11496. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11497. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11498. sleep(1);
  11499. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11500. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11501. }
  11502. // OCPPPH only, must announce CSU upgrade firmware
  11503. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11504. interLock.isUpdateFirmwareGoing = 0;
  11505. pthread_exit(NULL);
  11506. }
  11507. int handleCertificateSignedRequest(char *uuid, char *payload)
  11508. {
  11509. mtrace();
  11510. int result = PASS;
  11511. json_object *CertificateSigned;
  11512. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11513. CertificateSigned = json_tokener_parse(payload);
  11514. if(!is_error(CertificateSigned))
  11515. {
  11516. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11517. }
  11518. json_object_put(CertificateSigned);
  11519. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11520. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11521. fclose(fp);
  11522. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11523. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11524. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11525. sendCertificateSignedConfirmation(uuid);
  11526. return result;
  11527. }
  11528. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11529. {
  11530. mtrace();
  11531. int result = PASS;
  11532. json_object *DeleteCertificate;
  11533. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11534. DeleteCertificate = json_tokener_parse(payload);
  11535. if(!is_error(DeleteCertificate))
  11536. {
  11537. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11538. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11539. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11540. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11541. }
  11542. json_object_put(DeleteCertificate);
  11543. /*
  11544. * TODO: Delete certificateSigned process
  11545. */
  11546. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11547. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11548. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11549. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11550. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11551. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11552. sendDeleteCertificateConfirmation(uuid);
  11553. return result;
  11554. }
  11555. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11556. {
  11557. mtrace();
  11558. int result = PASS;
  11559. json_object *ExtendedTriggerMessage;
  11560. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11561. ExtendedTriggerMessage = json_tokener_parse(payload);
  11562. if(!is_error(ExtendedTriggerMessage))
  11563. {
  11564. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11565. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11566. {
  11567. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11568. }
  11569. else
  11570. {
  11571. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11572. }
  11573. }
  11574. json_object_put(ExtendedTriggerMessage);
  11575. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11576. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11577. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11578. {
  11579. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11580. }
  11581. else
  11582. {
  11583. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11584. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11585. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11586. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11587. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11588. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11589. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11590. {
  11591. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11592. }
  11593. else
  11594. {
  11595. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11596. }
  11597. }
  11598. sendExtendedTriggerMessageConfirmation(uuid);
  11599. //==========================
  11600. // Trigger message
  11601. //==========================
  11602. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11603. {
  11604. //sendBootNotificationRequest();
  11605. server_sign = FALSE;
  11606. }
  11607. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11608. {
  11609. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11610. }
  11611. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11612. {
  11613. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11614. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11615. {
  11616. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11617. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11618. }
  11619. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11620. }
  11621. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11622. {
  11623. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11624. }
  11625. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11626. {
  11627. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11628. {
  11629. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11630. }
  11631. else
  11632. {
  11633. for(int idx=0;idx< gunTotalNumber;idx++)
  11634. {
  11635. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11636. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11637. }
  11638. }
  11639. }
  11640. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11641. {
  11642. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11643. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11644. {
  11645. 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\" &");
  11646. }
  11647. }
  11648. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11649. {
  11650. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11651. {
  11652. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11653. }
  11654. else
  11655. {
  11656. for(int idx=0;idx< gunTotalNumber;idx++)
  11657. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11658. }
  11659. }
  11660. return result;
  11661. }
  11662. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11663. {
  11664. mtrace();
  11665. int result = PASS;
  11666. json_object *GetInstalledCertificateIds;
  11667. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11668. GetInstalledCertificateIds = json_tokener_parse(payload);
  11669. if(!is_error(GetInstalledCertificateIds))
  11670. {
  11671. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11672. }
  11673. json_object_put(GetInstalledCertificateIds);
  11674. /*
  11675. * TODO: Return installed certificate process
  11676. */
  11677. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11678. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11679. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11680. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11681. sendGetInstalledCertificateIdsConfirmation(uuid);
  11682. return result;
  11683. }
  11684. int handleGetLogRequest(char *uuid, char *payload)
  11685. {
  11686. mtrace();
  11687. int result = PASS;
  11688. json_object *GetLog;
  11689. DEBUG_INFO("handleGetLogRequest...\n");
  11690. GetLog = json_tokener_parse(payload);
  11691. if(!is_error(GetLog))
  11692. {
  11693. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11694. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11695. if(json_object_object_get(GetLog, "retries") != NULL)
  11696. {
  11697. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11698. }
  11699. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11700. {
  11701. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11702. }
  11703. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11704. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11705. {
  11706. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11707. }
  11708. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11709. {
  11710. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11711. }
  11712. }
  11713. json_object_put(GetLog);
  11714. /*
  11715. * TODO: Upload log process
  11716. */
  11717. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11718. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11719. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11720. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11721. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11722. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11723. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11724. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11725. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11726. sendGetLogConfirmation(uuid);
  11727. return result;
  11728. }
  11729. int handleInstallCertificateRequest(char *uuid, char *payload)
  11730. {
  11731. mtrace();
  11732. int result = PASS;
  11733. json_object *InstallCertificate;
  11734. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11735. InstallCertificate = json_tokener_parse(payload);
  11736. if(!is_error(InstallCertificate))
  11737. {
  11738. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11739. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11740. /*
  11741. * TODO: Install certificate process
  11742. */
  11743. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11744. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11745. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11746. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11747. sendInstallCertificateConfirmation(uuid);
  11748. }
  11749. json_object_put(InstallCertificate);
  11750. return result;
  11751. }
  11752. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11753. {
  11754. mtrace();
  11755. int result = PASS;
  11756. json_object *SignedUpdateFirmware;
  11757. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11758. SignedUpdateFirmware = json_tokener_parse(payload);
  11759. if(!is_error(SignedUpdateFirmware))
  11760. {
  11761. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11762. {
  11763. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11764. }
  11765. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11766. {
  11767. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11768. }
  11769. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11770. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11771. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11772. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11773. {
  11774. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11775. }
  11776. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11777. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11778. }
  11779. json_object_put(SignedUpdateFirmware);
  11780. /*
  11781. * TODO: Upgrade firmware process
  11782. */
  11783. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11784. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11785. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11786. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11787. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11788. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11789. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11790. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11791. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11792. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11793. sendInstallCertificateConfirmation(uuid);
  11794. return result;
  11795. }
  11796. int handleUnknownRequest(char *uuid, char *payload)
  11797. {
  11798. mtrace();
  11799. int result = PASS;
  11800. DEBUG_INFO("handleUnknownRequest...\n");
  11801. sendUnknownConfirmation(uuid);
  11802. result = PASS;
  11803. return result;
  11804. }
  11805. //==========================================
  11806. // Handle server response routine
  11807. //==========================================
  11808. void handleAuthorizeResponse(char *payload, int gun_index)
  11809. {
  11810. mtrace();
  11811. char expiryDatestr[30]={0};
  11812. char parentIdTagstr[20]={0};
  11813. char statusstr[20]={0};
  11814. int expiryDateISNULL=FALSE;
  11815. int parentIdTagISNULL=FALSE;
  11816. DEBUG_INFO("handleAuthorizeResponse...\n");
  11817. json_object *Authorize;
  11818. Authorize = json_tokener_parse(payload);
  11819. if(!is_error(Authorize))
  11820. {
  11821. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11822. {
  11823. // Required data
  11824. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11825. // Optional data
  11826. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11827. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11828. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11829. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11830. }
  11831. }
  11832. json_object_put(Authorize);
  11833. if(expiryDateISNULL == FALSE)
  11834. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11835. if(parentIdTagISNULL == FALSE)
  11836. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11837. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11838. //Update idTag information to authorization cache if supproted
  11839. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11840. {
  11841. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11842. }
  11843. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11844. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11845. authorizeRetryTimes = 0;
  11846. }
  11847. void handleBootNotificationResponse(char *payload, int gun_index)
  11848. {
  11849. mtrace();
  11850. char statusStr[12]={0};
  11851. char currentTimeStr[30]={0};
  11852. int intervalInt = 0;
  11853. DEBUG_INFO("handleBootNotificationResponse...\n");
  11854. json_object *BootNotification;
  11855. BootNotification = json_tokener_parse(payload);
  11856. if(!is_error(BootNotification))
  11857. {
  11858. // Required data
  11859. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11860. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11861. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11862. }
  11863. json_object_put(BootNotification);
  11864. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11865. BootNotificationInterval = intervalInt;
  11866. HeartBeatWaitTime = intervalInt;
  11867. //write back to ShmOCPP16DataPH->BootNotification
  11868. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11869. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11870. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11871. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11872. {
  11873. server_sign = TRUE;
  11874. server_pending =FALSE;
  11875. }
  11876. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11877. {
  11878. server_pending = TRUE;
  11879. }
  11880. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11881. srand(time(NULL));
  11882. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11883. SetOcppConnStatus(TRUE);
  11884. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11885. }
  11886. void handleDataTransferResponse(char *payload, int gun_index)
  11887. {
  11888. char sstr[160]={0};//sstr[200]={ 0 };
  11889. int c = 0;
  11890. char *loc;
  11891. DEBUG_INFO("handleDataTransferResponse ...\n");
  11892. loc = strstr(payload, "status");
  11893. c = 0;
  11894. while (loc[3+strlen("status")+c] != '\"')
  11895. {
  11896. sstr[c] = loc[3+strlen("status")+c];
  11897. c++;
  11898. }
  11899. sstr[c] = '\0';
  11900. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11901. }
  11902. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11903. {
  11904. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11905. //struct json_object *obj;
  11906. // obj = json_tokener_parse(payload);
  11907. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11908. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11909. //No fields are defined.
  11910. }
  11911. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11912. {
  11913. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11914. //struct json_object *obj;
  11915. // obj = json_tokener_parse(payload);
  11916. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11917. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11918. //No fields are defined.
  11919. }
  11920. void handleHeartbeatResponse(char *payload, int gun_index)
  11921. {
  11922. mtrace();
  11923. DEBUG_INFO("handleHeartbeatResponse...\n");
  11924. json_object *Heartbeat;
  11925. Heartbeat = json_tokener_parse(payload);
  11926. if(!is_error(Heartbeat))
  11927. {
  11928. // Required data
  11929. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11930. }
  11931. json_object_put(Heartbeat);
  11932. if(FirstHeartBeat == 0)
  11933. {
  11934. FirstHeartBeat = 1;
  11935. DEBUG_INFO("FirstHeartBeat \n");
  11936. }
  11937. HeartBeatWithNOResponse = 0;
  11938. clientTime.Heartbeat=time((time_t*)NULL);
  11939. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11940. }
  11941. void handleMeterValuesResponse(char *payload, int gun_index)
  11942. {
  11943. mtrace();
  11944. DEBUG_INFO("handleMeterValuesResponse...\n");
  11945. }
  11946. void handleStartTransactionResponse(char *payload, int gun_index)
  11947. {
  11948. mtrace();
  11949. //int transactionIdInt = 0;
  11950. FILE *outfile;
  11951. char data[100]={0};
  11952. DEBUG_INFO("handleStartTransactionResponse...\n");
  11953. json_object *StartTransaction;
  11954. StartTransaction = json_tokener_parse(payload);
  11955. if(!is_error(StartTransaction))
  11956. {
  11957. // Required data
  11958. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11959. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11960. // Optional data
  11961. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11962. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11963. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11964. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11965. }
  11966. json_object_put(StartTransaction);
  11967. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11968. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11969. //-----------Start : write to the Queue TransactionId file -----------------//
  11970. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11971. {}
  11972. else
  11973. {
  11974. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11975. if(log == NULL)
  11976. {
  11977. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11978. return ;
  11979. }
  11980. else
  11981. {
  11982. fclose(log);
  11983. }
  11984. }
  11985. // open file for writing
  11986. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11987. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11988. {
  11989. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11990. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11991. fputs(data, outfile);
  11992. fclose (outfile);
  11993. }
  11994. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11995. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11996. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11997. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11998. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11999. }
  12000. void handleStatusNotificationResponse(char *payload, int gun_index)
  12001. {
  12002. mtrace();
  12003. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12004. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12005. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12006. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12007. }
  12008. void handleStopTransactionnResponse(char *payload, int gun_index)
  12009. {
  12010. mtrace();
  12011. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12012. json_object *StopTransaction;
  12013. StopTransaction = json_tokener_parse(payload);
  12014. if(!is_error(StopTransaction))
  12015. {
  12016. // Optional data
  12017. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12018. {
  12019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12020. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12022. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12024. }
  12025. }
  12026. json_object_put(StopTransaction);
  12027. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12028. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12029. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12030. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12031. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12032. }
  12033. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12034. {
  12035. mtrace();
  12036. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12037. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12038. }
  12039. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12040. {
  12041. mtrace();
  12042. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12043. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12044. }
  12045. void handleSignCertificateResponse(char *payload, int gun_index)
  12046. {
  12047. mtrace();
  12048. DEBUG_INFO("handleSignCertificateResponse...\n");
  12049. json_object *SignCertificate;
  12050. SignCertificate = json_tokener_parse(payload);
  12051. if(!is_error(SignCertificate))
  12052. {
  12053. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12054. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12055. }
  12056. json_object_put(SignCertificate);
  12057. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12058. }
  12059. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12060. {
  12061. mtrace();
  12062. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12063. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12064. }
  12065. //==========================================
  12066. // Handle Error routine
  12067. //==========================================
  12068. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12069. {
  12070. mtrace();
  12071. #ifdef SystemLogMessage
  12072. DEBUG_INFO("errorCode: %s\n", errorCode);
  12073. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12074. DEBUG_INFO("errorDetails: %s\n", payload);
  12075. #endif
  12076. }
  12077. //===============================================
  12078. // Common routine
  12079. //===============================================
  12080. int initialConfigurationTable(void)
  12081. {
  12082. //clock_t start_t, end_t, total_t;
  12083. FILE *fp;
  12084. FILE *outfile;
  12085. char str[512]={0};
  12086. char sstr[256]={0};
  12087. int c = 0;
  12088. char *loc;
  12089. int confVersion = 9;
  12090. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12091. //start_t = clock();
  12092. //printf("Starting of the program, start_t = %ld\n", start_t);
  12093. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12094. // Check configuration file size is correct
  12095. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12096. {
  12097. struct stat st;
  12098. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12099. if(st.st_size < 3100)
  12100. {
  12101. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12102. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12103. }
  12104. }
  12105. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12106. {
  12107. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12108. if(outfile == NULL)
  12109. {
  12110. DEBUG_INFO("Error opening file\n");
  12111. return FALSE;
  12112. }
  12113. /*Core Profile*/
  12114. //AllowOfflineTxForUnknownId
  12115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12119. //AuthorizationCacheEnabled
  12120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12124. //AuthorizeRemoteTxRequests
  12125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12129. //BlinkRepeat
  12130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12134. //ClockAlignedDataInterval
  12135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12139. //ConnectionTimeOut
  12140. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12144. //GetConfigurationMaxKeys
  12145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12149. // HeartbeatInterval
  12150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12154. // LightIntensity
  12155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12159. // LocalAuthorizeOffline
  12160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12164. // LocalPreAuthorize
  12165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12169. // MaxEnergyOnInvalidId
  12170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12174. // MeterValuesAlignedData
  12175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12179. else
  12180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12182. // MeterValuesAlignedDataMaxLength
  12183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12187. else
  12188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12190. // MeterValuesSampledData
  12191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12195. else
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12198. // MeterValuesSampledDataMaxLength
  12199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12203. else
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12206. // MeterValueSampleInterval
  12207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12211. // MinimumStatusDuration
  12212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12215. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12217. // NumberOfConnectors
  12218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12221. {
  12222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12223. }
  12224. else
  12225. {
  12226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12227. }
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12229. // ResetRetries
  12230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12234. // ConnectorPhaseRotation
  12235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12239. // ConnectorPhaseRotationMaxLength
  12240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12244. // StopTransactionOnEVSideDisconnect
  12245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12249. // StopTransactionOnInvalidId
  12250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12254. // StopTxnAlignedData
  12255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12259. // StopTxnAlignedDataMaxLength
  12260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12264. // StopTxnSampledData
  12265. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12269. else
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12272. // StopTxnSampledDataMaxLength
  12273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12276. {
  12277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12278. }
  12279. else
  12280. {
  12281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12282. }
  12283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12284. // SupportedFeatureProfiles
  12285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12289. // SupportedFeatureProfilesMaxLength
  12290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12294. // TransactionMessageAttempts
  12295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12298. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12300. // TransactionMessageRetryInterval
  12301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12304. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12306. // UnlockConnectorOnEVSideDisconnect
  12307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12311. // WebSocketPingInterval
  12312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12316. // QueueOffLineMeterValues
  12317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12321. // AuthorizationKey
  12322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12326. // SecurityProfile
  12327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12331. // DefaultPrice
  12332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12336. // CustomDisplayCostAndPrice
  12337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12341. // CustomIdleFeeAfterStop
  12342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12346. // SystemUptimeSec
  12347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  12348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  12349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  12350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  12351. // Configuration Version
  12352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12356. //* Local Auth List Management Profile*/
  12357. #if 0
  12358. //For OCTT Test Case
  12359. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12362. #endif
  12363. #if 1
  12364. //LocalAuthListEnabled
  12365. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12369. #endif
  12370. //LocalAuthListMaxLength
  12371. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12375. //SendLocalListMaxLength
  12376. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12380. //ReserveConnectorZeroSupported
  12381. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12385. //* Smart Charging Profile */
  12386. //ChargeProfileMaxStackLevel
  12387. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12391. // ChargingScheduleAllowedChargingRateUnit
  12392. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12396. // ChargingScheduleMaxPeriods
  12397. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12401. // ConnectorSwitch3to1PhaseSupported
  12402. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12406. // MaxChargingProfilesInstalled
  12407. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12411. fclose(outfile);
  12412. }
  12413. else
  12414. {
  12415. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12416. char keystr[60]={0};
  12417. char readonlystr[10]={0};
  12418. char valuestr[256]={0};
  12419. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12420. if(fp == NULL) {
  12421. DEBUG_INFO("Error opening file");
  12422. return FALSE;
  12423. }
  12424. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12425. {
  12426. //DEBUG_INFO("Get Configuration \n");
  12427. if(strlen(str) > 0)
  12428. {
  12429. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12430. //*************************key*********************************/
  12431. if(strstr(str, "key") != NULL)
  12432. {
  12433. loc = strstr(str, "key");
  12434. c = 0;
  12435. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12436. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12437. {
  12438. sstr[c] = loc[strlen("key")+3+c];
  12439. c++;
  12440. }
  12441. sstr[c] = '\0';
  12442. strcpy(keystr,sstr);
  12443. }
  12444. //*************************readonly*********************************/
  12445. if(strstr(str, "readonly") != NULL)
  12446. {
  12447. loc = strstr(str, "readonly");
  12448. c = 0;
  12449. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12450. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12451. {
  12452. sstr[c] = loc[strlen("readonly")+2+c];
  12453. c++;
  12454. }
  12455. sstr[c] = '\0';
  12456. strcpy(readonlystr,sstr);
  12457. }
  12458. //*************************value*********************************/
  12459. if(strstr(str, "value") != NULL)
  12460. {
  12461. loc = strstr(str, "value");
  12462. c = 0;
  12463. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12464. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12465. {
  12466. sstr[c] = loc[strlen("value")+3+c];
  12467. c++;
  12468. }
  12469. sstr[c] = '\0';
  12470. strcpy(valuestr,sstr);
  12471. }
  12472. // DEBUG_INFO("keystr=%s\n",keystr);
  12473. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12474. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12475. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12476. {
  12477. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12480. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12481. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12482. }
  12483. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12484. {
  12485. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12486. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12487. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12488. }
  12489. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12490. {
  12491. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12493. }
  12494. if(strcmp(keystr, "BlinkRepeat") == 0)
  12495. {
  12496. //Charger.BlinkRepeat = Integer.parseInt(value);
  12497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12499. }
  12500. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12501. {
  12502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12504. }
  12505. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12506. {
  12507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12509. }
  12510. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12511. {
  12512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12514. }
  12515. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12516. {
  12517. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12519. HeartBeatWaitTime = atoi(valuestr);
  12520. }
  12521. if(strcmp(keystr, "LightIntensity") == 0)
  12522. {
  12523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12525. }
  12526. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12527. {
  12528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12530. }
  12531. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12532. {
  12533. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12535. }
  12536. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12537. {
  12538. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12540. }
  12541. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12542. {
  12543. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12545. }
  12546. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12547. {
  12548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12550. }
  12551. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12552. {
  12553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12555. }
  12556. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12557. {
  12558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12560. }
  12561. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12562. {
  12563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12565. }
  12566. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12567. {
  12568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12570. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12571. }
  12572. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12573. {
  12574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12576. }
  12577. if(strcmp(keystr, "ResetRetries") == 0)
  12578. {
  12579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12581. }
  12582. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12583. {
  12584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12586. }
  12587. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12588. {
  12589. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12591. }
  12592. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12593. {
  12594. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12596. }
  12597. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12598. {
  12599. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12601. }
  12602. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12603. {
  12604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12606. }
  12607. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12608. {
  12609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12611. }
  12612. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12613. {
  12614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12615. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12616. }
  12617. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12618. {
  12619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12621. }
  12622. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12623. {
  12624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12626. }
  12627. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12628. {
  12629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12631. }
  12632. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12633. {
  12634. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12635. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12636. TransactionMessageAttemptsValue = atoi(valuestr);
  12637. }
  12638. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12639. {
  12640. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12642. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12643. }
  12644. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12645. {
  12646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12648. }
  12649. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12650. {
  12651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12653. }
  12654. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12655. {
  12656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12658. }
  12659. if(strcmp(keystr, "AuthorizationKey") == 0)
  12660. {
  12661. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12662. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12664. }
  12665. if(strcmp(keystr, "SecurityProfile") == 0)
  12666. {
  12667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12668. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12670. }
  12671. if(strcmp(keystr, "DefaultPrice") == 0)
  12672. {
  12673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12675. }
  12676. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12677. {
  12678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12680. }
  12681. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12682. {
  12683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12685. }
  12686. if(strcmp(keystr, "SystemUptimeSec") == 0)
  12687. {
  12688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  12690. }
  12691. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12692. {
  12693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12695. }
  12696. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12697. {
  12698. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12700. }
  12701. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12702. {
  12703. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12705. }
  12706. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12707. {
  12708. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12710. }
  12711. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12712. {
  12713. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12715. }
  12716. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12717. {
  12718. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12720. }
  12721. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12722. {
  12723. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12725. }
  12726. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12727. {
  12728. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12730. }
  12731. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12732. {
  12733. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12735. }
  12736. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12737. {
  12738. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12740. }
  12741. }
  12742. }
  12743. fclose(fp);
  12744. }
  12745. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12746. {
  12747. return PASS;
  12748. }
  12749. else
  12750. {
  12751. return FAIL;
  12752. }
  12753. }
  12754. void StoreConfigurationTable(void)
  12755. {
  12756. FILE *outfile;
  12757. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12758. if(outfile == NULL)
  12759. {
  12760. DEBUG_INFO("Error opening file");
  12761. return ;
  12762. }
  12763. /*Core Profile*/
  12764. //AllowOfflineTxForUnknownId
  12765. /*
  12766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12767. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12770. */
  12771. //DEBUG_INFO("data=%s\n",data);
  12772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12773. //AuthorizationCacheEnabled
  12774. /*
  12775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12778. */
  12779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12780. //AuthorizeRemoteTxRequests
  12781. /*
  12782. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12785. */
  12786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12787. //BlinkRepeat
  12788. /*
  12789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12792. */
  12793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12794. //ClockAlignedDataInterval
  12795. /*
  12796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12799. */
  12800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12801. //ConnectionTimeOut
  12802. /*
  12803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12806. */
  12807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12808. //GetConfigurationMaxKeys
  12809. /*
  12810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12813. */
  12814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12815. // HeartbeatInterval
  12816. /*
  12817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12820. */
  12821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12822. // LightIntensity
  12823. /*
  12824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12827. */
  12828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12829. // LocalAuthorizeOffline
  12830. /*
  12831. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12834. */
  12835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12836. // LocalPreAuthorize
  12837. /*
  12838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12841. */
  12842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12843. // MaxEnergyOnInvalidId
  12844. /*
  12845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12848. */
  12849. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12851. // MeterValuesAlignedData
  12852. /*
  12853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12856. */
  12857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12858. // MeterValuesAlignedDataMaxLength
  12859. /*
  12860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12863. */
  12864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12865. // MeterValuesSampledData
  12866. /*
  12867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12870. */
  12871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12872. // MeterValuesSampledDataMaxLength
  12873. /*
  12874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12877. */
  12878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12879. // MeterValueSampleInterval
  12880. /*
  12881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12884. */
  12885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12886. // MinimumStatusDuration
  12887. /*
  12888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12891. */
  12892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12893. // NumberOfConnectors
  12894. /*
  12895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12898. {
  12899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12900. }
  12901. else
  12902. {
  12903. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12904. }
  12905. */
  12906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12907. // ResetRetries
  12908. /*
  12909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12912. */
  12913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12914. // ConnectorPhaseRotation
  12915. /*
  12916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12919. */
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12921. // ConnectorPhaseRotationMaxLength
  12922. /*
  12923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12926. */
  12927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12928. // StopTransactionOnEVSideDisconnect
  12929. /*
  12930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12933. */
  12934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12935. // StopTransactionOnInvalidId
  12936. /*
  12937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12940. */
  12941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12942. // StopTxnAlignedData
  12943. /*
  12944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12947. */
  12948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12949. // StopTxnAlignedDataMaxLength
  12950. /*
  12951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12954. */
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12956. // StopTxnSampledData
  12957. /*
  12958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12961. */
  12962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12963. // StopTxnSampledDataMaxLength
  12964. /*
  12965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12968. */
  12969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12970. // SupportedFeatureProfiles
  12971. /*
  12972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12975. */
  12976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12977. // SupportedFeatureProfilesMaxLength
  12978. /*
  12979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12982. */
  12983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12984. // TransactionMessageAttempts
  12985. /*
  12986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12989. */
  12990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12991. // TransactionMessageRetryInterval
  12992. /*
  12993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12996. */
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12998. // UnlockConnectorOnEVSideDisconnect
  12999. /*
  13000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13003. */
  13004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13005. // WebSocketPingInterval
  13006. /*
  13007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13010. */
  13011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13012. // QueueOffLineMeterValues
  13013. /*
  13014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13017. */
  13018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13019. // AuthorizationKey
  13020. /*
  13021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13024. */
  13025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13026. // SecurityProfile
  13027. /*
  13028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13031. */
  13032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13033. // DefaultPrice
  13034. /*
  13035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13038. */
  13039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13040. // CustomDisplayCostAndPrice
  13041. /*
  13042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13045. */
  13046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13047. // CustomIdleFeeAfterStop
  13048. /*
  13049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13052. */
  13053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13054. // SystemUptimeSec
  13055. /*
  13056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13059. */
  13060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13061. // ConfigurationVersion
  13062. /*
  13063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13066. */
  13067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13068. //* Local Auth List Management Profile*/
  13069. //LocalAuthListEnabled
  13070. /*
  13071. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13074. */
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13076. //LocalAuthListMaxLength
  13077. /*
  13078. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13081. */
  13082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13083. //SendLocalListMaxLength
  13084. /*
  13085. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13088. */
  13089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13090. //ReserveConnectorZeroSupported
  13091. /*
  13092. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13095. */
  13096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13097. //* Smart Charging Profile */
  13098. //ChargeProfileMaxStackLevel
  13099. /*
  13100. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13103. */
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13105. // ChargingScheduleAllowedChargingRateUnit
  13106. /*
  13107. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13110. */
  13111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13112. // ChargingScheduleMaxPeriods
  13113. /*
  13114. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13117. */
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13119. // ConnectorSwitch3to1PhaseSupported
  13120. /*
  13121. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13124. */
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13126. // MaxChargingProfilesInstalled
  13127. /*
  13128. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13131. */
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13133. fclose(outfile);
  13134. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13135. }
  13136. void getKeyValue(char *keyReq)
  13137. {
  13138. int isEmpty = FALSE;
  13139. int isKnowKey = FALSE;
  13140. DEBUG_INFO("keyReq = %s\n", keyReq);
  13141. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13142. isEmpty = TRUE;
  13143. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13144. {
  13145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13147. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13148. {
  13149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13150. }
  13151. else
  13152. {
  13153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13154. }
  13155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13156. isKnowKey = TRUE;
  13157. }
  13158. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13159. {
  13160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13162. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13163. {
  13164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13165. }
  13166. else
  13167. {
  13168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13169. }
  13170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13171. isKnowKey = TRUE;
  13172. }
  13173. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13174. {
  13175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13177. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13178. {
  13179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13180. }
  13181. else
  13182. {
  13183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13184. }
  13185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13186. isKnowKey = TRUE;
  13187. }
  13188. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13189. {
  13190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13192. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13193. {
  13194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13195. }
  13196. else
  13197. {
  13198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13199. }
  13200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13201. isKnowKey = TRUE;
  13202. }
  13203. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13204. {
  13205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13207. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13208. {
  13209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13210. }
  13211. else
  13212. {
  13213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13214. }
  13215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13216. isKnowKey = TRUE;
  13217. }
  13218. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13219. {
  13220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13222. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13223. {
  13224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13225. }
  13226. else
  13227. {
  13228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13229. }
  13230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13231. isKnowKey = TRUE;
  13232. }
  13233. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13234. {
  13235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13237. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13238. {
  13239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13240. }
  13241. else
  13242. {
  13243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13244. }
  13245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13246. isKnowKey = TRUE;
  13247. }
  13248. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13249. {
  13250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13253. {
  13254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13255. }
  13256. else
  13257. {
  13258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13259. }
  13260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13261. isKnowKey = TRUE;
  13262. }
  13263. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13264. {
  13265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13267. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13268. {
  13269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13270. }
  13271. else
  13272. {
  13273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13274. }
  13275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13276. isKnowKey = TRUE;
  13277. }
  13278. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13279. {
  13280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13282. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13283. {
  13284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13285. }
  13286. else
  13287. {
  13288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13289. }
  13290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13291. isKnowKey = TRUE;
  13292. }
  13293. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13294. {
  13295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13297. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13298. {
  13299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13300. }
  13301. else
  13302. {
  13303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13304. }
  13305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13306. isKnowKey = TRUE;
  13307. }
  13308. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13309. {
  13310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13313. {
  13314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13315. }
  13316. else
  13317. {
  13318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13319. }
  13320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13321. isKnowKey = TRUE;
  13322. }
  13323. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13324. {
  13325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13328. {
  13329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13330. }
  13331. else
  13332. {
  13333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13334. }
  13335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13336. isKnowKey = TRUE;
  13337. }
  13338. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13339. {
  13340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13343. {
  13344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13345. }
  13346. else
  13347. {
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13349. }
  13350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13351. isKnowKey = TRUE;
  13352. }
  13353. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13354. {
  13355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13358. {
  13359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13360. }
  13361. else
  13362. {
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13364. }
  13365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13366. isKnowKey = TRUE;
  13367. }
  13368. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13369. {
  13370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13373. {
  13374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13375. }
  13376. else
  13377. {
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13379. }
  13380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13381. isKnowKey = TRUE;
  13382. }
  13383. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13384. {
  13385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13387. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13388. {
  13389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13390. }
  13391. else
  13392. {
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13394. }
  13395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13396. isKnowKey = TRUE;
  13397. }
  13398. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13399. {
  13400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13402. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13403. {
  13404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13405. }
  13406. else
  13407. {
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13409. }
  13410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13411. isKnowKey = TRUE;
  13412. }
  13413. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13414. {
  13415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13418. {
  13419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13420. }
  13421. else
  13422. {
  13423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13424. }
  13425. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13427. isKnowKey = TRUE;
  13428. }
  13429. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13430. {
  13431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13433. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13434. {
  13435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13436. }
  13437. else
  13438. {
  13439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13440. }
  13441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13442. isKnowKey = TRUE;
  13443. }
  13444. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13445. {
  13446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13449. {
  13450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13451. }
  13452. else
  13453. {
  13454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13455. }
  13456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13457. isKnowKey = TRUE;
  13458. }
  13459. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13460. {
  13461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13464. {
  13465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13466. }
  13467. else
  13468. {
  13469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13470. }
  13471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13472. isKnowKey = TRUE;
  13473. }
  13474. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13475. {
  13476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13479. {
  13480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13481. }
  13482. else
  13483. {
  13484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13485. }
  13486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13487. isKnowKey = TRUE;
  13488. }
  13489. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13490. {
  13491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13494. {
  13495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13496. }
  13497. else
  13498. {
  13499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13500. }
  13501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13502. isKnowKey = TRUE;
  13503. }
  13504. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13505. {
  13506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13509. {
  13510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13511. }
  13512. else
  13513. {
  13514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13515. }
  13516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13517. isKnowKey = TRUE;
  13518. }
  13519. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13520. {
  13521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13523. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13524. {
  13525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13526. }
  13527. else
  13528. {
  13529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13530. }
  13531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13532. isKnowKey = TRUE;
  13533. }
  13534. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13535. {
  13536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13539. {
  13540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13541. }
  13542. else
  13543. {
  13544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13545. }
  13546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13547. isKnowKey = TRUE;
  13548. }
  13549. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13550. {
  13551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13554. {
  13555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13556. }
  13557. else
  13558. {
  13559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13560. }
  13561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13562. isKnowKey = TRUE;
  13563. }
  13564. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13565. {
  13566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13569. {
  13570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13571. }
  13572. else
  13573. {
  13574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13575. }
  13576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13577. isKnowKey = TRUE;
  13578. }
  13579. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13580. {
  13581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13584. {
  13585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13586. }
  13587. else
  13588. {
  13589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13590. }
  13591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13592. isKnowKey = TRUE;
  13593. }
  13594. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13595. {
  13596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13598. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13599. {
  13600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13601. }
  13602. else
  13603. {
  13604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13605. }
  13606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13607. isKnowKey = TRUE;
  13608. }
  13609. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13610. {
  13611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13614. {
  13615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13616. }
  13617. else
  13618. {
  13619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13620. }
  13621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13622. isKnowKey = TRUE;
  13623. }
  13624. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13625. {
  13626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13628. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13629. {
  13630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13631. }
  13632. else
  13633. {
  13634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13635. }
  13636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13637. isKnowKey = TRUE;
  13638. }
  13639. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13640. {
  13641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13643. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13644. {
  13645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13646. }
  13647. else
  13648. {
  13649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13650. }
  13651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13652. isKnowKey = TRUE;
  13653. }
  13654. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13655. {
  13656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13658. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13659. {
  13660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13661. }
  13662. else
  13663. {
  13664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13665. }
  13666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13667. isKnowKey = TRUE;
  13668. }
  13669. /*
  13670. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13671. {
  13672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13674. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13675. {
  13676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13677. }
  13678. else
  13679. {
  13680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13681. }
  13682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13683. isKnowKey = TRUE;
  13684. }*/
  13685. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13686. {
  13687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13689. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13690. {
  13691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13692. }
  13693. else
  13694. {
  13695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13696. }
  13697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13698. isKnowKey = TRUE;
  13699. }
  13700. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13701. {
  13702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13704. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13705. {
  13706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13707. }
  13708. else
  13709. {
  13710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13711. }
  13712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13713. isKnowKey = TRUE;
  13714. }
  13715. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13716. {
  13717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13719. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13720. {
  13721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13722. }
  13723. else
  13724. {
  13725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13726. }
  13727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13728. isKnowKey = TRUE;
  13729. }
  13730. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13731. {
  13732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13734. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13735. {
  13736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13737. }
  13738. else
  13739. {
  13740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13741. }
  13742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13743. isKnowKey = TRUE;
  13744. }
  13745. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  13746. {
  13747. struct sysinfo s_info;
  13748. int error = sysinfo(&s_info);
  13749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  13750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  13751. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  13752. {
  13753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  13754. }
  13755. else
  13756. {
  13757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  13758. }
  13759. if(error != 0)
  13760. {
  13761. DEBUG_WARN("System uptime get error: %d\n", error);
  13762. }
  13763. else
  13764. {
  13765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  13766. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  13767. }
  13768. isKnowKey = TRUE;
  13769. }
  13770. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13771. {
  13772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13774. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13775. {
  13776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13777. }
  13778. else
  13779. {
  13780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13781. }
  13782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13783. isKnowKey = TRUE;
  13784. }
  13785. #if 1
  13786. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13787. {
  13788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13790. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13791. {
  13792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13793. }
  13794. else
  13795. {
  13796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13797. }
  13798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13799. isKnowKey = TRUE;
  13800. }
  13801. #endif
  13802. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13803. {
  13804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13806. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13807. {
  13808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13809. }
  13810. else
  13811. {
  13812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13813. }
  13814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13815. isKnowKey = TRUE;
  13816. }
  13817. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13818. {
  13819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13821. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13822. {
  13823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13824. }
  13825. else
  13826. {
  13827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13828. }
  13829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13830. isKnowKey = TRUE;
  13831. }
  13832. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13833. {
  13834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13836. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13837. {
  13838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13839. }
  13840. else
  13841. {
  13842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13843. }
  13844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13845. isKnowKey = TRUE;
  13846. }
  13847. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13848. {
  13849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13851. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13852. {
  13853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13854. }
  13855. else
  13856. {
  13857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13858. }
  13859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13860. isKnowKey = TRUE;
  13861. }
  13862. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13863. {
  13864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13866. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13867. {
  13868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13869. }
  13870. else
  13871. {
  13872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13873. }
  13874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13875. isKnowKey = TRUE;
  13876. }
  13877. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13878. {
  13879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13881. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13882. {
  13883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13884. }
  13885. else
  13886. {
  13887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13888. }
  13889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13890. isKnowKey = TRUE;
  13891. }
  13892. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13893. {
  13894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13896. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13897. {
  13898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13899. }
  13900. else
  13901. {
  13902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13903. }
  13904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13905. isKnowKey = TRUE;
  13906. }
  13907. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13908. {
  13909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13911. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13912. {
  13913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13914. }
  13915. else
  13916. {
  13917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13918. }
  13919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13920. isKnowKey = TRUE;
  13921. }
  13922. //=========================================================
  13923. if(!isEmpty && !isKnowKey)
  13924. {
  13925. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13926. strcpy(unknownkey[UnknownKeynum], keyReq);
  13927. UnknownKeynum = UnknownKeynum + 1;
  13928. }
  13929. }
  13930. void processUnkownKey(void)
  13931. {
  13932. DEBUG_INFO("processUnkownKey...\n");
  13933. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13934. for(int index=0; index < UnknownKeynum; index++)
  13935. {
  13936. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13937. {
  13938. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13939. }
  13940. }
  13941. }
  13942. int setKeyValue(char *key, char *value)
  13943. {
  13944. int isSuccess = NotSupported;
  13945. int check_ascii=0;
  13946. char str[256]={0};
  13947. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13948. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13949. {
  13950. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13952. {
  13953. strcpy(str, (const char*)value);
  13954. for(int i = 0; str[i]; i++){
  13955. str[i] = tolower(str[i]);
  13956. }
  13957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13958. isSuccess = ConfigurationStatus_Accepted;
  13959. }
  13960. else
  13961. {
  13962. isSuccess = ConfigurationStatus_Rejected;
  13963. }
  13964. }
  13965. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13966. {
  13967. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13969. {
  13970. strcpy(str, (const char*)value);
  13971. for(int i = 0; str[i]; i++){
  13972. str[i] = tolower(str[i]);
  13973. }
  13974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13975. isSuccess = ConfigurationStatus_Accepted;
  13976. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13977. }
  13978. else
  13979. {
  13980. isSuccess = ConfigurationStatus_Rejected;
  13981. }
  13982. }
  13983. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13984. {
  13985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13986. {
  13987. strcpy(str, (const char*)value);
  13988. for(int i = 0; str[i]; i++)
  13989. {
  13990. str[i] = tolower(str[i]);
  13991. }
  13992. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13993. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13994. isSuccess = ConfigurationStatus_Accepted;
  13995. }
  13996. else
  13997. {
  13998. isSuccess = ConfigurationStatus_Rejected;
  13999. }
  14000. }
  14001. if(strcmp(key, "BlinkRepeat") == 0)
  14002. {
  14003. //Charger.BlinkRepeat = Integer.parseInt(value);
  14004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14005. {
  14006. check_ascii = value[0];
  14007. if( (check_ascii < 48) || (check_ascii > 57) )
  14008. {
  14009. isSuccess = ConfigurationStatus_Rejected;
  14010. }
  14011. else
  14012. {
  14013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14014. isSuccess = ConfigurationStatus_Accepted;
  14015. }
  14016. }
  14017. else
  14018. {
  14019. isSuccess = ConfigurationStatus_Rejected;
  14020. }
  14021. }
  14022. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14023. {
  14024. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14025. {
  14026. check_ascii = value[0];
  14027. if( (check_ascii < 48) || (check_ascii > 57) )
  14028. {
  14029. isSuccess = ConfigurationStatus_Rejected;
  14030. }
  14031. else
  14032. {
  14033. if((atoi(value) == 0) || (atoi(value) >= 10))
  14034. {
  14035. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14036. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14037. isSuccess = ConfigurationStatus_Accepted;
  14038. }
  14039. else
  14040. isSuccess = ConfigurationStatus_Rejected;
  14041. }
  14042. }
  14043. else
  14044. {
  14045. isSuccess = ConfigurationStatus_Rejected;
  14046. }
  14047. }
  14048. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14049. {
  14050. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14051. {
  14052. check_ascii = value[0];
  14053. if( (check_ascii < 48) || (check_ascii > 57) )
  14054. {
  14055. isSuccess = ConfigurationStatus_Rejected;
  14056. }
  14057. else
  14058. {
  14059. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14060. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14061. isSuccess = ConfigurationStatus_Accepted;
  14062. }
  14063. }
  14064. else
  14065. {
  14066. isSuccess = ConfigurationStatus_Rejected;
  14067. }
  14068. }
  14069. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14070. {
  14071. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14072. {
  14073. check_ascii = value[0];
  14074. if( (check_ascii < 48) || (check_ascii > 57) )
  14075. {
  14076. isSuccess = ConfigurationStatus_Rejected;
  14077. }
  14078. else
  14079. {
  14080. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14082. isSuccess = ConfigurationStatus_Accepted;
  14083. }
  14084. }
  14085. else
  14086. {
  14087. isSuccess = ConfigurationStatus_Rejected;
  14088. }
  14089. }
  14090. if(strcmp(key, "HeartbeatInterval") == 0)
  14091. {
  14092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14093. {
  14094. check_ascii = value[0];
  14095. if( (check_ascii < 48) || (check_ascii > 57) )
  14096. {
  14097. isSuccess = ConfigurationStatus_Rejected;
  14098. }
  14099. else
  14100. {
  14101. if((atoi(value) == 0) || (atoi(value) >= 10))
  14102. {
  14103. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14104. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14105. HeartBeatWaitTime = atoi(value);
  14106. isSuccess = ConfigurationStatus_Accepted;
  14107. }
  14108. else
  14109. {
  14110. isSuccess = ConfigurationStatus_Rejected;
  14111. }
  14112. }
  14113. }
  14114. else
  14115. {
  14116. isSuccess = ConfigurationStatus_Rejected;
  14117. }
  14118. }
  14119. if(strcmp(key, "LightIntensity") == 0)
  14120. {
  14121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14122. {
  14123. check_ascii = value[0];
  14124. if( (check_ascii < 48) || (check_ascii > 57) )
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. else
  14129. {
  14130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14131. isSuccess = ConfigurationStatus_Accepted;
  14132. }
  14133. }
  14134. else
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. }
  14139. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14140. {
  14141. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14142. {
  14143. strcpy(str, (const char*)value);
  14144. for(int i = 0; str[i]; i++)
  14145. {
  14146. str[i] = tolower(str[i]);
  14147. }
  14148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14149. isSuccess = ConfigurationStatus_Accepted;
  14150. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14151. }
  14152. else
  14153. {
  14154. isSuccess = ConfigurationStatus_Rejected;
  14155. }
  14156. }
  14157. if(strcmp(key, "LocalPreAuthorize") == 0)
  14158. {
  14159. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14160. {
  14161. strcpy(str, (const char*)value);
  14162. for(int i = 0; str[i]; i++)
  14163. {
  14164. str[i] = tolower(str[i]);
  14165. }
  14166. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14167. isSuccess = ConfigurationStatus_Accepted;
  14168. }
  14169. else
  14170. {
  14171. isSuccess = ConfigurationStatus_Rejected;
  14172. }
  14173. }
  14174. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14175. {
  14176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14177. {
  14178. check_ascii = value[0];
  14179. if( (check_ascii < 48) || (check_ascii > 57) )
  14180. {
  14181. isSuccess = ConfigurationStatus_Rejected;
  14182. }
  14183. else
  14184. {
  14185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14186. isSuccess = ConfigurationStatus_Accepted;
  14187. }
  14188. }
  14189. else
  14190. {
  14191. isSuccess = ConfigurationStatus_Rejected;
  14192. }
  14193. }
  14194. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14195. {
  14196. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14197. {
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14199. isSuccess = ConfigurationStatus_Accepted;
  14200. }
  14201. else
  14202. {
  14203. isSuccess = ConfigurationStatus_Rejected;
  14204. }
  14205. }
  14206. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14207. {
  14208. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14209. {
  14210. check_ascii = value[0];
  14211. if( (check_ascii < 48) || (check_ascii > 57) )
  14212. {
  14213. isSuccess = ConfigurationStatus_Rejected;
  14214. }
  14215. else
  14216. {
  14217. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14219. isSuccess = ConfigurationStatus_Accepted;
  14220. }
  14221. }
  14222. else
  14223. {
  14224. isSuccess = ConfigurationStatus_Rejected;
  14225. }
  14226. }
  14227. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14228. {
  14229. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14230. {
  14231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14232. isSuccess = ConfigurationStatus_Accepted;
  14233. }
  14234. else
  14235. {
  14236. isSuccess = ConfigurationStatus_Rejected;
  14237. }
  14238. }
  14239. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14240. {
  14241. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14242. {
  14243. check_ascii = value[0];
  14244. if( (check_ascii < 48) || (check_ascii > 57) )
  14245. {
  14246. isSuccess = ConfigurationStatus_Rejected;
  14247. }
  14248. else
  14249. {
  14250. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14252. isSuccess = ConfigurationStatus_Accepted;
  14253. }
  14254. }
  14255. else
  14256. {
  14257. isSuccess = ConfigurationStatus_Rejected;
  14258. }
  14259. }
  14260. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14261. {
  14262. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14263. {
  14264. check_ascii = value[0];
  14265. if( (check_ascii < 48) || (check_ascii > 57) )
  14266. {
  14267. isSuccess = ConfigurationStatus_Rejected;
  14268. }
  14269. else
  14270. {
  14271. if((atoi(value) == 0) || (atoi(value) >= 10))
  14272. {
  14273. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14274. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14275. isSuccess = ConfigurationStatus_Accepted;
  14276. }
  14277. else
  14278. {
  14279. isSuccess = ConfigurationStatus_Rejected;
  14280. }
  14281. }
  14282. }
  14283. else
  14284. {
  14285. isSuccess = ConfigurationStatus_Rejected;
  14286. }
  14287. }
  14288. if(strcmp(key, "MinimumStatusDuration") == 0)
  14289. {
  14290. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14291. {
  14292. check_ascii = value[0];
  14293. if( (check_ascii < 48) || (check_ascii > 57) )
  14294. {
  14295. isSuccess = ConfigurationStatus_Rejected;
  14296. }
  14297. else
  14298. {
  14299. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14300. {
  14301. isSuccess = ConfigurationStatus_Rejected;
  14302. }
  14303. else
  14304. {
  14305. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14306. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14307. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14308. isSuccess = ConfigurationStatus_Accepted;
  14309. }
  14310. }
  14311. }
  14312. else
  14313. {
  14314. isSuccess = ConfigurationStatus_Rejected;
  14315. }
  14316. }
  14317. if(strcmp(key, "NumberOfConnectors") == 0)
  14318. {
  14319. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14320. {
  14321. check_ascii = value[0];
  14322. if( (check_ascii < 48) || (check_ascii > 57) )
  14323. {
  14324. isSuccess = ConfigurationStatus_Rejected;
  14325. }
  14326. else
  14327. {
  14328. //Charger.ResetRetries = Integer.parseInt(value);
  14329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14330. isSuccess = ConfigurationStatus_Accepted;
  14331. }
  14332. }
  14333. else
  14334. {
  14335. isSuccess = ConfigurationStatus_Rejected;
  14336. }
  14337. }
  14338. if(strcmp(key, "ResetRetries") == 0)
  14339. {
  14340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14341. {
  14342. check_ascii = value[0];
  14343. if( (check_ascii < 48) || (check_ascii > 57) )
  14344. {
  14345. isSuccess = ConfigurationStatus_Rejected;
  14346. }
  14347. else
  14348. {
  14349. //Charger.ResetRetries = Integer.parseInt(value);
  14350. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14351. isSuccess = ConfigurationStatus_Accepted;
  14352. }
  14353. }
  14354. else
  14355. {
  14356. isSuccess = ConfigurationStatus_Rejected;
  14357. }
  14358. }
  14359. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14360. {
  14361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14362. {
  14363. strcpy(str, (const char*)value);
  14364. for(int i = 0; str[i]; i++)
  14365. {
  14366. str[i] = tolower(str[i]);
  14367. }
  14368. if(strcmp(str, "notapplicable")== 0)
  14369. {
  14370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14371. isSuccess = ConfigurationStatus_Accepted;
  14372. }
  14373. else if(strcmp(str, "unknown")== 0)
  14374. {
  14375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14376. isSuccess = ConfigurationStatus_Accepted;
  14377. }
  14378. else if(strcmp(str, "rst")== 0)
  14379. {
  14380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14381. isSuccess = ConfigurationStatus_Accepted;
  14382. }
  14383. else if(strcmp(str, "rts")== 0)
  14384. {
  14385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14386. isSuccess = ConfigurationStatus_Accepted;
  14387. }
  14388. else if(strcmp(str, "srt")== 0)
  14389. {
  14390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14391. isSuccess = ConfigurationStatus_Accepted;
  14392. }
  14393. else if(strcmp(str, "str")== 0)
  14394. {
  14395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14396. isSuccess = ConfigurationStatus_Accepted;
  14397. }
  14398. else if(strcmp(str, "trs")== 0)
  14399. {
  14400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14401. isSuccess = ConfigurationStatus_Accepted;
  14402. }
  14403. else if(strcmp(str, "tsr")== 0)
  14404. {
  14405. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14406. isSuccess = ConfigurationStatus_Accepted;
  14407. }
  14408. else
  14409. {
  14410. isSuccess = ConfigurationStatus_Rejected;
  14411. }
  14412. }
  14413. else
  14414. {
  14415. isSuccess = ConfigurationStatus_Rejected;
  14416. }
  14417. }
  14418. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14419. {
  14420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14421. {
  14422. check_ascii = value[0];
  14423. if( (check_ascii < 48) || (check_ascii > 57) )
  14424. {
  14425. isSuccess = ConfigurationStatus_Rejected;
  14426. }
  14427. else
  14428. {
  14429. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14430. isSuccess = ConfigurationStatus_Accepted;
  14431. }
  14432. }
  14433. else
  14434. {
  14435. isSuccess = ConfigurationStatus_Rejected;
  14436. }
  14437. }
  14438. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14439. {
  14440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14441. {
  14442. strcpy(str, (const char*)value);
  14443. for(int i = 0; str[i]; i++)
  14444. {
  14445. str[i] = tolower(str[i]);
  14446. }
  14447. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14449. isSuccess = ConfigurationStatus_Accepted;
  14450. }
  14451. else
  14452. {
  14453. isSuccess = ConfigurationStatus_Rejected;
  14454. }
  14455. }
  14456. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14457. {
  14458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14459. {
  14460. strcpy(str, (const char*)value);
  14461. for(int i = 0; str[i]; i++)
  14462. {
  14463. str[i] = tolower(str[i]);
  14464. }
  14465. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14467. isSuccess = ConfigurationStatus_Accepted;
  14468. }
  14469. else
  14470. {
  14471. isSuccess = ConfigurationStatus_Rejected;
  14472. }
  14473. }
  14474. if(strcmp(key, "StopTxnAlignedData") == 0)
  14475. {
  14476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14477. {
  14478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14479. isSuccess = ConfigurationStatus_Accepted;
  14480. }
  14481. else
  14482. {
  14483. isSuccess = ConfigurationStatus_Rejected;
  14484. }
  14485. }
  14486. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14487. {
  14488. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14489. {
  14490. check_ascii = value[0];
  14491. if( (check_ascii < 48) || (check_ascii > 57) )
  14492. {
  14493. isSuccess = ConfigurationStatus_Rejected;
  14494. }
  14495. else
  14496. {
  14497. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14498. isSuccess = ConfigurationStatus_Accepted;
  14499. }
  14500. }
  14501. else
  14502. {
  14503. isSuccess = ConfigurationStatus_Rejected;
  14504. }
  14505. }
  14506. if(strcmp(key, "StopTxnSampledData") == 0)
  14507. {
  14508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14509. {
  14510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14511. isSuccess = ConfigurationStatus_Accepted;
  14512. }
  14513. else
  14514. {
  14515. isSuccess = ConfigurationStatus_Rejected;
  14516. }
  14517. }
  14518. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14519. {
  14520. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14521. {
  14522. check_ascii = value[0];
  14523. if( (check_ascii < 48) || (check_ascii > 57) )
  14524. {
  14525. isSuccess = ConfigurationStatus_Rejected;
  14526. }
  14527. else
  14528. {
  14529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14530. isSuccess = ConfigurationStatus_Accepted;
  14531. }
  14532. }
  14533. else
  14534. {
  14535. isSuccess = ConfigurationStatus_Rejected;
  14536. }
  14537. }
  14538. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14539. {
  14540. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14541. {
  14542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14543. isSuccess = ConfigurationStatus_Accepted;
  14544. }
  14545. else
  14546. {
  14547. isSuccess = ConfigurationStatus_Rejected;
  14548. }
  14549. }
  14550. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14551. {
  14552. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14553. {
  14554. check_ascii = value[0];
  14555. if( (check_ascii < 48) || (check_ascii > 57) )
  14556. {
  14557. isSuccess = ConfigurationStatus_Rejected;
  14558. }
  14559. else
  14560. {
  14561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14562. isSuccess = ConfigurationStatus_Accepted;
  14563. }
  14564. }
  14565. else
  14566. {
  14567. isSuccess = ConfigurationStatus_Rejected;
  14568. }
  14569. }
  14570. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14571. {
  14572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14573. {
  14574. check_ascii = value[0];
  14575. if( (check_ascii < 48) || (check_ascii > 57) )
  14576. {
  14577. isSuccess = ConfigurationStatus_Rejected;
  14578. }
  14579. else
  14580. {
  14581. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14583. TransactionMessageAttemptsValue = atoi(value);
  14584. isSuccess = ConfigurationStatus_Accepted;
  14585. }
  14586. }
  14587. else
  14588. {
  14589. isSuccess = ConfigurationStatus_Rejected;
  14590. }
  14591. }
  14592. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14593. {
  14594. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14595. {
  14596. check_ascii = value[0];
  14597. if( (check_ascii < 48) || (check_ascii > 57) )
  14598. {
  14599. isSuccess = ConfigurationStatus_Rejected;
  14600. }
  14601. else
  14602. {
  14603. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14604. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14605. TransactionMessageRetryIntervalValue = atoi(value);
  14606. isSuccess = ConfigurationStatus_Accepted;
  14607. }
  14608. }
  14609. else
  14610. {
  14611. isSuccess = ConfigurationStatus_Rejected;
  14612. }
  14613. }
  14614. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14615. {
  14616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14617. {
  14618. strcpy(str, (const char*)value);
  14619. for(int i = 0; str[i]; i++)
  14620. {
  14621. str[i] = tolower(str[i]);
  14622. }
  14623. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14625. isSuccess = ConfigurationStatus_Accepted;
  14626. }
  14627. else
  14628. {
  14629. isSuccess = ConfigurationStatus_Rejected;
  14630. }
  14631. }
  14632. if(strcmp(key, "WebSocketPingInterval") == 0)
  14633. {
  14634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14635. {
  14636. check_ascii = value[0];
  14637. if( (check_ascii < 48) || (check_ascii > 57) )
  14638. {
  14639. isSuccess = ConfigurationStatus_Rejected;
  14640. }
  14641. else
  14642. {
  14643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14644. isSuccess = ConfigurationStatus_Accepted;
  14645. }
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14653. {
  14654. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14655. {
  14656. strcpy(str, (const char*)value);
  14657. for(int i = 0; str[i]; i++)
  14658. {
  14659. str[i] = tolower(str[i]);
  14660. }
  14661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14662. isSuccess = ConfigurationStatus_Accepted;
  14663. }
  14664. else
  14665. {
  14666. isSuccess = ConfigurationStatus_Rejected;
  14667. }
  14668. }
  14669. if(strcmp(key, "AuthorizationKey") == 0)
  14670. {
  14671. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14672. {
  14673. strcpy(str, (const char*)value);
  14674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14675. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14676. isSuccess = ConfigurationStatus_Accepted;
  14677. }
  14678. else
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. }
  14683. if(strcmp(key, "SecurityProfile") == 0)
  14684. {
  14685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14686. {
  14687. check_ascii = value[0];
  14688. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14689. {
  14690. isSuccess = ConfigurationStatus_Rejected;
  14691. }
  14692. else if(check_ascii == 0x33)
  14693. {
  14694. isSuccess = NotSupported;
  14695. }
  14696. else
  14697. {
  14698. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14699. {
  14700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14701. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14702. isSuccess = ConfigurationStatus_Accepted;
  14703. }
  14704. else
  14705. isSuccess = ConfigurationStatus_Rejected;
  14706. }
  14707. }
  14708. else
  14709. {
  14710. isSuccess = ConfigurationStatus_Rejected;
  14711. }
  14712. }
  14713. if(strcmp(key, "DefaultPrice") == 0)
  14714. {
  14715. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14716. {
  14717. strcpy(str, (const char*)value);
  14718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14719. isSuccess = ConfigurationStatus_Accepted;
  14720. }
  14721. else
  14722. {
  14723. isSuccess = ConfigurationStatus_Rejected;
  14724. }
  14725. }
  14726. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14727. {
  14728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14729. {
  14730. strcpy(str, (const char*)value);
  14731. for(int i = 0; str[i]; i++)
  14732. {
  14733. str[i] = tolower(str[i]);
  14734. }
  14735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14736. isSuccess = ConfigurationStatus_Accepted;
  14737. }
  14738. else
  14739. {
  14740. isSuccess = ConfigurationStatus_Rejected;
  14741. }
  14742. }
  14743. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14744. {
  14745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14746. {
  14747. strcpy(str, (const char*)value);
  14748. for(int i = 0; str[i]; i++)
  14749. {
  14750. str[i] = tolower(str[i]);
  14751. }
  14752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14753. isSuccess = ConfigurationStatus_Accepted;
  14754. }
  14755. else
  14756. {
  14757. isSuccess = ConfigurationStatus_Rejected;
  14758. }
  14759. }
  14760. if(strcmp(key, "SystemUptimeSec") == 0)
  14761. {
  14762. isSuccess = NotSupported;
  14763. }
  14764. #if 0
  14765. //For OCPP Test Case
  14766. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14767. {
  14768. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14769. {
  14770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14771. isSuccess = ConfigurationStatus_Accepted;
  14772. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14773. }
  14774. else
  14775. {
  14776. isSuccess = ConfigurationStatus_Rejected;
  14777. }
  14778. }
  14779. #endif
  14780. #if 1
  14781. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14782. {
  14783. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14784. {
  14785. strcpy(str, (const char*)value);
  14786. for(int i = 0; str[i]; i++)
  14787. {
  14788. str[i] = tolower(str[i]);
  14789. }
  14790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14791. isSuccess = ConfigurationStatus_Accepted;
  14792. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14793. }
  14794. else
  14795. {
  14796. isSuccess = ConfigurationStatus_Rejected;
  14797. }
  14798. }
  14799. #endif
  14800. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14801. {
  14802. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14803. {
  14804. check_ascii = value[0];
  14805. if( (check_ascii < 48) || (check_ascii > 57) )
  14806. {
  14807. isSuccess = ConfigurationStatus_Rejected;
  14808. }
  14809. else
  14810. {
  14811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14812. isSuccess = ConfigurationStatus_Accepted;
  14813. }
  14814. }
  14815. else
  14816. {
  14817. isSuccess = ConfigurationStatus_Rejected;
  14818. }
  14819. }
  14820. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14821. {
  14822. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14823. {
  14824. check_ascii = value[0];
  14825. if( (check_ascii < 48) || (check_ascii > 57) )
  14826. {
  14827. isSuccess = ConfigurationStatus_Rejected;
  14828. }
  14829. else
  14830. {
  14831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14832. isSuccess = ConfigurationStatus_Accepted;
  14833. }
  14834. }
  14835. else
  14836. {
  14837. isSuccess = ConfigurationStatus_Rejected;
  14838. }
  14839. }
  14840. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14841. {
  14842. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14843. {
  14844. strcpy(str, (const char*)value);
  14845. for(int i = 0; str[i]; i++)
  14846. {
  14847. str[i] = tolower(str[i]);
  14848. }
  14849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14850. isSuccess = ConfigurationStatus_Accepted;
  14851. }
  14852. else
  14853. {
  14854. isSuccess = ConfigurationStatus_Rejected;
  14855. }
  14856. }
  14857. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14858. {
  14859. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14860. {
  14861. check_ascii = value[0];
  14862. if( (check_ascii < 48) || (check_ascii > 57) )
  14863. {
  14864. isSuccess = ConfigurationStatus_Rejected;
  14865. }
  14866. else
  14867. {
  14868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14869. isSuccess = ConfigurationStatus_Accepted;
  14870. }
  14871. }
  14872. else
  14873. {
  14874. isSuccess = ConfigurationStatus_Rejected;
  14875. }
  14876. }
  14877. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14878. {
  14879. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14880. {
  14881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14882. isSuccess = ConfigurationStatus_Accepted;
  14883. }
  14884. else
  14885. {
  14886. isSuccess = ConfigurationStatus_Rejected;
  14887. }
  14888. }
  14889. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14890. {
  14891. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14892. {
  14893. check_ascii = value[0];
  14894. if( (check_ascii < 48) || (check_ascii > 57) )
  14895. {
  14896. isSuccess = ConfigurationStatus_Rejected;
  14897. }
  14898. else
  14899. {
  14900. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14901. isSuccess = ConfigurationStatus_Accepted;
  14902. }
  14903. }
  14904. else
  14905. {
  14906. isSuccess = ConfigurationStatus_Rejected;
  14907. }
  14908. }
  14909. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14910. {
  14911. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14912. {
  14913. strcpy(str, (const char*)value);
  14914. for(int i = 0; str[i]; i++)
  14915. {
  14916. str[i] = tolower(str[i]);
  14917. }
  14918. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14919. isSuccess = ConfigurationStatus_Accepted;
  14920. }
  14921. else
  14922. {
  14923. isSuccess = ConfigurationStatus_Rejected;
  14924. }
  14925. }
  14926. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14927. {
  14928. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14929. {
  14930. check_ascii = value[0];
  14931. if( (check_ascii < 48) || (check_ascii > 57) )
  14932. {
  14933. isSuccess = ConfigurationStatus_Rejected;
  14934. }
  14935. else
  14936. {
  14937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14938. isSuccess = ConfigurationStatus_Accepted;
  14939. }
  14940. }
  14941. else
  14942. {
  14943. isSuccess = ConfigurationStatus_Rejected;
  14944. }
  14945. }
  14946. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14947. return isSuccess;
  14948. }
  14949. int TransactionMessageAttemptsGet(void)
  14950. {
  14951. return TransactionMessageAttemptsValue;
  14952. }
  14953. int FirstHeartBeatResponse(void)
  14954. {
  14955. return FirstHeartBeat;
  14956. }
  14957. int TransactionMessageRetryIntervalGet(void)
  14958. {
  14959. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14960. }
  14961. int ReadHttpStatus(int sock)
  14962. {
  14963. //char c;
  14964. char buff[1024]="",*ptr=buff+1;
  14965. int bytes_received, status;
  14966. DEBUG_INFO("Begin Response ..\n");
  14967. while((bytes_received = recv(sock, ptr, 1, 0))){
  14968. if(bytes_received==-1){
  14969. perror("ReadHttpStatus");
  14970. exit(1);
  14971. }
  14972. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14973. ptr++;
  14974. }
  14975. *ptr=0;
  14976. ptr=buff+1;
  14977. sscanf(ptr,"%*s %d ", &status);
  14978. DEBUG_INFO("%s\n",ptr);
  14979. DEBUG_INFO("status=%d\n",status);
  14980. DEBUG_INFO("End Response ..\n");
  14981. return (bytes_received>0)?status:0;
  14982. }
  14983. //the only filed that it parsed is 'Content-Length'
  14984. int ParseHeader(int sock)
  14985. {
  14986. //char c;
  14987. char buff[1024]="",*ptr=buff+4;
  14988. int bytes_received;
  14989. DEBUG_INFO("Begin HEADER ..\n");
  14990. while((bytes_received = recv(sock, ptr, 1, 0))){
  14991. if(bytes_received==-1){
  14992. perror("Parse Header");
  14993. exit(1);
  14994. }
  14995. if(
  14996. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14997. (ptr[-1]=='\r') && (*ptr=='\n' )
  14998. ) break;
  14999. ptr++;
  15000. }
  15001. *ptr=0;
  15002. ptr=buff+4;
  15003. //printf("%s",ptr);
  15004. if(bytes_received){
  15005. ptr=strstr(ptr,"Content-Length:");
  15006. if(ptr){
  15007. sscanf(ptr,"%*s %d",&bytes_received);
  15008. }else
  15009. bytes_received=-1; //unknown size
  15010. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15011. }
  15012. DEBUG_INFO("End HEADER ..\n");
  15013. return bytes_received ;
  15014. }
  15015. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15016. {
  15017. int result = TRUE;
  15018. char rmFileCmd[100]={0};
  15019. char FilePath[100]={0};
  15020. char ftpbuf[200];
  15021. int systemresult;
  15022. sprintf(FilePath,"/mnt/%s",filename);
  15023. system("ping 8.8.8.8 &");
  15024. if((access(FilePath,F_OK))!=-1)
  15025. {
  15026. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15027. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15028. system(rmFileCmd);
  15029. }
  15030. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15031. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15032. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15033. systemresult = system(ftpbuf);
  15034. if(systemresult != 0)
  15035. {
  15036. DEBUG_INFO("http DownLoad error!\n");
  15037. result = FALSE;
  15038. }
  15039. system("pkill ping");
  15040. return result;
  15041. }
  15042. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15043. {
  15044. int result = TRUE;
  15045. char rmFileCmd[100]={0};
  15046. char FilePath[100]={0};
  15047. char ftpbuf[200];
  15048. int systemresult;
  15049. sprintf(FilePath,"/mnt/%s",filename);
  15050. system("ping 8.8.8.8 &");
  15051. if((access(FilePath,F_OK))!=-1)
  15052. {
  15053. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15054. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15055. system(rmFileCmd);
  15056. }
  15057. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15058. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15059. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15060. systemresult = system(ftpbuf);
  15061. if(systemresult != 0)
  15062. {
  15063. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15064. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15065. systemresult = system(ftpbuf);
  15066. if(systemresult != 0)
  15067. {
  15068. DEBUG_WARN("wget error!\n");
  15069. result = FALSE;
  15070. }
  15071. }
  15072. system("pkill ping");
  15073. return result;
  15074. }
  15075. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15076. {
  15077. char rmFileCmd[100]={0};
  15078. char FilePath[100]={0};
  15079. char buf[512];
  15080. int systemresult = 0;
  15081. //DEBUG_INFO("filename=%s\n",filename);
  15082. //DEBUG_INFO("url=%s\n",url);
  15083. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15084. if((access(FilePath,F_OK))!=-1)
  15085. {
  15086. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15087. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15088. system(rmFileCmd);
  15089. }
  15090. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15091. if(fp == NULL)
  15092. {
  15093. DEBUG_INFO("log is NULL\n");
  15094. return FALSE;
  15095. }
  15096. else
  15097. {
  15098. fprintf(fp, "%s\n", url);
  15099. fprintf(fp, "%s\n", filename);
  15100. fclose(fp);
  15101. }
  15102. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15103. if(phpFP == NULL)
  15104. {
  15105. DEBUG_INFO("PHP upload fail.\n");
  15106. return FALSE;
  15107. }
  15108. else
  15109. {
  15110. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15111. {
  15112. if(strstr(buf, "result") != NULL)
  15113. {
  15114. sscanf(buf, "result: %d", &systemresult);
  15115. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15116. }
  15117. }
  15118. pclose(phpFP);
  15119. }
  15120. if(systemresult != 1)
  15121. {
  15122. DEBUG_INFO("HTTP upload error!\n");
  15123. return FALSE;
  15124. }
  15125. return TRUE;
  15126. }
  15127. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15128. {
  15129. struct hostent* server;
  15130. char *IPbuffer;
  15131. char ftpbuf[200];
  15132. int systemresult;
  15133. // To retrieve host information
  15134. server = gethostbyname(location);
  15135. // To convert an Internet network
  15136. // address into ASCII string
  15137. IPbuffer = inet_ntoa(*((struct in_addr*)
  15138. server->h_addr_list[0]));
  15139. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15140. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15141. /* format : ftpput -u username -p passwd IP target source*/
  15142. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15143. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15144. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15145. systemresult = system(ftpbuf);
  15146. DEBUG_INFO("systemresult=%d\n",systemresult);
  15147. if(systemresult != 0)
  15148. {
  15149. DEBUG_INFO("ftpput error!\n");
  15150. return FALSE;
  15151. }
  15152. return TRUE;
  15153. }
  15154. int GetOcppServerURL()
  15155. {
  15156. int result = FALSE;
  15157. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15158. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15159. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15160. struct yuarel url;
  15161. char urlStr[512];
  15162. // OCPPPH only
  15163. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15164. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15165. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15166. {
  15167. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15168. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15169. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15170. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15171. if(yuarel_parse(&url, urlStr) != -1)
  15172. {
  15173. sprintf(OcppProtocol, "%s", url.scheme);
  15174. sprintf(OcppHost, "%s", url.host);
  15175. if(url.path == NULL)
  15176. OcppTempPath[0] = '\0';
  15177. else
  15178. sprintf(OcppTempPath, "%s", url.path);
  15179. if(url.port == 0)
  15180. {
  15181. if(strcmp(OcppProtocol, "wss") == 0)
  15182. OcppPort = 443;
  15183. else
  15184. OcppPort = 80;
  15185. }
  15186. else
  15187. OcppPort = url.port;
  15188. result = TRUE;
  15189. }
  15190. }
  15191. else
  15192. {
  15193. strcpy(OcppHost,"");
  15194. }
  15195. return result;
  15196. }
  15197. int GetOcppPath()
  15198. {
  15199. int result = FALSE;
  15200. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15201. {
  15202. if(OcppTempPath == NULL)
  15203. {
  15204. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15205. }
  15206. else
  15207. {
  15208. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15209. }
  15210. result = TRUE;
  15211. goto End;
  15212. }
  15213. else
  15214. {
  15215. strcpy(OcppPath,"");
  15216. }
  15217. End:
  15218. return result;
  15219. }
  15220. int GetOcppPort()
  15221. {
  15222. return OcppPort;
  15223. }
  15224. int GetOcppConnStatus(void)
  15225. {
  15226. return ShmOCPP16DataPH->OcppConnStatus;
  15227. }
  15228. void SetOcppConnStatus(uint8_t status)
  15229. {
  15230. ShmOCPP16DataPH->OcppConnStatus = status;
  15231. }
  15232. int GetHeartBeatWithNOResponse(void)
  15233. {
  15234. return HeartBeatWithNOResponse;
  15235. }
  15236. void SetHeartBeatWithNOResponse(void)
  15237. {
  15238. HeartBeatWithNOResponse = 0;
  15239. }
  15240. void GetStartTransactionIdTag(int gun_index)
  15241. {
  15242. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15243. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15244. }
  15245. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15246. {
  15247. char ch;
  15248. FILE *fptr1;
  15249. int temptransactionId;
  15250. char str[100]={0};
  15251. temptransactionId = 0;
  15252. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15253. {
  15254. DEBUG_INFO("IdTag is empty.\n");
  15255. return temptransactionId;
  15256. }
  15257. /*------ Read the file ----------------*/
  15258. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15259. if (!fptr1)
  15260. {
  15261. DEBUG_INFO("QueueTransactionId file open error.\n");
  15262. //printf(" File not found or unable to open the input file!!\n");
  15263. return temptransactionId;
  15264. }
  15265. ch=fgetc(fptr1);
  15266. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15267. rewind(fptr1);
  15268. if(ch!=EOF)
  15269. {
  15270. // printf("%c",ch);
  15271. while (fgets(str, 100, fptr1) != NULL)
  15272. {
  15273. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15274. if(str[0]=='\0')
  15275. {
  15276. break;
  15277. }
  15278. char *revbuf[8] = {0}; // Variable store string split
  15279. int num = 0;// Quantity after string split
  15280. DEBUG_INFO("Transaction queue data= %s\n", str);
  15281. splitstring(str,",",revbuf,&num); // String split
  15282. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15283. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15284. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15285. DEBUG_INFO("------------------------------\n");
  15286. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15287. {
  15288. if(isStopTransaction)
  15289. {
  15290. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15291. {
  15292. temptransactionId = atoi(revbuf[2]);
  15293. //break;
  15294. }
  15295. }
  15296. else
  15297. {
  15298. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15299. {
  15300. temptransactionId = atoi(revbuf[2]);
  15301. //break;
  15302. }
  15303. }
  15304. }
  15305. }
  15306. }
  15307. else
  15308. DEBUG_INFO("EOF\n");
  15309. fclose(fptr1);
  15310. /*------- End of reading ---------------*/
  15311. return temptransactionId;
  15312. }
  15313. void SetTransactionIdZero(int transactionId)
  15314. {
  15315. char ch;
  15316. FILE *fptr1, *fptr2;
  15317. int temptransactionId = 0;
  15318. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15319. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15320. if (!fptr1)
  15321. {
  15322. //printf(" File not found or unable to open the input file!!\n");
  15323. return ;
  15324. }
  15325. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15326. if (!fptr2)
  15327. {
  15328. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15329. fclose(fptr1);
  15330. return ;
  15331. }
  15332. ch=fgetc(fptr1);
  15333. rewind(fptr1);
  15334. if(ch!=EOF)
  15335. {
  15336. // copy all contents to the temporary file except the specific line
  15337. while (fgets(str, 100, fptr1) != NULL)
  15338. {
  15339. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15340. if(str[0]=='\0')
  15341. {
  15342. break;
  15343. }
  15344. char *revbuf[8] = {0};
  15345. int num = 0;
  15346. strcpy(strtemp, str);
  15347. splitstring(str,",",revbuf,&num);
  15348. if(revbuf[2][0] != '\0')
  15349. {
  15350. temptransactionId = atoi(revbuf[2]);
  15351. if(transactionId != temptransactionId)
  15352. {
  15353. fprintf(fptr2, "%s\n", strtemp);
  15354. }
  15355. }
  15356. }
  15357. }
  15358. fclose(fptr1);
  15359. fclose(fptr2);
  15360. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15361. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15362. /*------ Read the file ----------------*/
  15363. }
  15364. int InternetDisconnect(void)
  15365. {
  15366. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15367. }
  15368. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15369. void storeTempStopTransaction(int gun_index)
  15370. {
  15371. char guid[37]={0};
  15372. int tempIndex = 0;
  15373. char TempStopTransaction[256];
  15374. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15375. DEBUG_INFO("storeTempStopTransaction...\n");
  15376. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15377. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15378. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15379. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15380. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15381. {
  15382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15383. {
  15384. tempIndex = ((gun_index==2) ? 1: 0);
  15385. }
  15386. else
  15387. {
  15388. tempIndex = gun_index;
  15389. }
  15390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15391. {
  15392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15393. {
  15394. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15395. }
  15396. }// END OF CHAdeMO_QUANTITY
  15397. }
  15398. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15399. {
  15400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15401. {
  15402. tempIndex = ((gun_index==2) ? 1: 0);
  15403. }
  15404. else
  15405. {
  15406. tempIndex = gun_index;
  15407. }
  15408. for (int index = 0; index < CCS_QUANTITY; index++)
  15409. {
  15410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15411. {
  15412. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15413. }
  15414. }// END OF CCS_QUANTITY
  15415. }
  15416. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15417. {
  15418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15419. {
  15420. tempIndex = ((gun_index==2) ? 1: 0);
  15421. }
  15422. else
  15423. {
  15424. tempIndex = gun_index;
  15425. }
  15426. for (int index = 0; index < GB_QUANTITY; index++)
  15427. {
  15428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15429. {
  15430. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15431. }
  15432. }// END OF GB_QUANTITY
  15433. }
  15434. else if(gunType[gun_index] == GUN_TYPE_DO)
  15435. {
  15436. tempIndex = gun_index;
  15437. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15438. {
  15439. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15440. {
  15441. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15442. }
  15443. }
  15444. }
  15445. else
  15446. {
  15447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15448. {
  15449. tempIndex = 2;
  15450. }
  15451. else
  15452. {
  15453. tempIndex = gun_index;
  15454. }
  15455. for (int index = 0; index < AC_QUANTITY; index++)
  15456. {
  15457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15458. {
  15459. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15460. }
  15461. }// END OF AC_QUANTITY
  15462. }
  15463. //Stop Transaction Time
  15464. struct timeval tmnow;
  15465. struct tm *tm;
  15466. char buf[28];//, usec_buf[6];
  15467. gettimeofday(&tmnow, NULL);
  15468. time_t t;
  15469. t = time(NULL);
  15470. /*UTC time and date*/
  15471. tm = gmtime(&t);
  15472. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15474. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15476. random_uuid(guid);
  15477. /***********************************transactionData******************************************************/
  15478. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15480. //=================================
  15481. //1. Transaction_Begin
  15482. //=================================
  15483. //============================== Energy.Active.Import.Interval ===========================================
  15484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15485. {
  15486. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15489. 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*/]);
  15490. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15491. 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))
  15492. {
  15493. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15494. }
  15495. else
  15496. {
  15497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15498. }
  15499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15501. }
  15502. //=================================
  15503. //2. Transaction_End
  15504. //=================================
  15505. //2.1====================================== Current.Import L1 ==============================================
  15506. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15507. {
  15508. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15509. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15510. {
  15511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15512. {
  15513. tempIndex = ((gun_index==2) ? 1: 0);
  15514. }
  15515. else
  15516. {
  15517. tempIndex = gun_index;
  15518. }
  15519. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15520. {
  15521. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15522. {
  15523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15524. }
  15525. }// End of for CHAdeMO_QUANTITY
  15526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15527. }
  15528. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15529. {
  15530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15531. {
  15532. tempIndex = ((gun_index==2) ? 1: 0);
  15533. }
  15534. else
  15535. {
  15536. tempIndex = gun_index;
  15537. }
  15538. for (int index = 0; index < CCS_QUANTITY; index++)
  15539. {
  15540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15541. {
  15542. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15543. }
  15544. }// End of for CCS_QUANTITY
  15545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15546. }
  15547. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15548. {
  15549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15550. {
  15551. tempIndex = ((gun_index==2) ? 1: 0);
  15552. }
  15553. else
  15554. {
  15555. tempIndex = gun_index;
  15556. }
  15557. for (int index = 0; index < GB_QUANTITY; index++)
  15558. {
  15559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15560. {
  15561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15562. }
  15563. }// End of for GB_QUANTITY
  15564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15565. }
  15566. else if(gunType[gun_index] == GUN_TYPE_DO)
  15567. {
  15568. tempIndex = gun_index;
  15569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15570. {
  15571. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15572. {
  15573. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15574. }
  15575. }
  15576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15577. }
  15578. else
  15579. {
  15580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15581. {
  15582. tempIndex = 2;
  15583. }
  15584. else
  15585. {
  15586. tempIndex = gun_index;
  15587. }
  15588. for (int index = 0; index < AC_QUANTITY; index++)
  15589. {
  15590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15591. {
  15592. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15593. }
  15594. }// End of for AC_QUANTITY
  15595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15596. }
  15597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15600. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15603. }
  15604. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15605. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15606. {
  15607. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15608. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15609. {
  15610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15611. {
  15612. tempIndex = ((gun_index==2) ? 1: 0);
  15613. }
  15614. else
  15615. {
  15616. tempIndex = gun_index;
  15617. }
  15618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15619. {
  15620. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15621. {
  15622. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15623. }
  15624. }// END OF CHAdeMO_QUANTITY
  15625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15626. }
  15627. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15628. {
  15629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15630. {
  15631. tempIndex = ((gun_index==2) ? 1: 0);
  15632. }
  15633. else
  15634. {
  15635. tempIndex = gun_index;
  15636. }
  15637. for (int index = 0; index < CCS_QUANTITY; index++)
  15638. {
  15639. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15640. {
  15641. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15642. }
  15643. }// END OF CCS_QUANTITY
  15644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15645. }
  15646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15647. {
  15648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15649. {
  15650. tempIndex = ((gun_index==2) ? 1: 0);
  15651. }
  15652. else
  15653. {
  15654. tempIndex = gun_index;
  15655. }
  15656. for (int index = 0; index < GB_QUANTITY; index++)
  15657. {
  15658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15659. {
  15660. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15661. }
  15662. }// END OF GB_QUANTITY
  15663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15664. }
  15665. else if(gunType[gun_index] == GUN_TYPE_DO)
  15666. {
  15667. tempIndex = gun_index;
  15668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15669. {
  15670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15671. {
  15672. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15673. }
  15674. }
  15675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15676. }
  15677. else
  15678. {
  15679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15680. {
  15681. tempIndex = 2;
  15682. }
  15683. else
  15684. {
  15685. tempIndex = gun_index;
  15686. }
  15687. for (int index = 0; index < AC_QUANTITY; index++)
  15688. {
  15689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15690. {
  15691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15692. }
  15693. }// END OF AC_QUANTITY
  15694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15695. }
  15696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15699. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15702. }
  15703. //2.3====================================== Power.Active.Import =========================================
  15704. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15705. {
  15706. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15707. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15708. {
  15709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15710. {
  15711. tempIndex = ((gun_index==2) ? 1: 0);
  15712. }
  15713. else
  15714. {
  15715. tempIndex = gun_index;
  15716. }
  15717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15718. {
  15719. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15720. {
  15721. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15722. }
  15723. } // End for CHAdeMO_QUANTITY
  15724. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15725. }
  15726. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15727. {
  15728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15729. {
  15730. tempIndex = ((gun_index==2) ? 1: 0);
  15731. }
  15732. else
  15733. {
  15734. tempIndex = gun_index;
  15735. }
  15736. for (int index = 0; index < CCS_QUANTITY; index++)
  15737. {
  15738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15739. {
  15740. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15741. }
  15742. } // END for CCS_QUANTITY
  15743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15744. }
  15745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15746. {
  15747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15748. {
  15749. tempIndex = ((gun_index==2) ? 1: 0);
  15750. }
  15751. else
  15752. {
  15753. tempIndex = gun_index;
  15754. }
  15755. for (int index = 0; index < GB_QUANTITY; index++)
  15756. {
  15757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15758. {
  15759. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15760. }
  15761. }// END for GB_QUANTITY
  15762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15763. }
  15764. else if(gunType[gun_index] == GUN_TYPE_DO)
  15765. {
  15766. tempIndex = gun_index;
  15767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15768. {
  15769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15770. {
  15771. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15772. }
  15773. }
  15774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15775. }
  15776. else
  15777. {
  15778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15779. {
  15780. tempIndex = 2;
  15781. }
  15782. else
  15783. {
  15784. tempIndex = gun_index;
  15785. }
  15786. for (int index = 0; index < AC_QUANTITY; index++)
  15787. {
  15788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15789. {
  15790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15791. }
  15792. } // END for AC_QUANTITY
  15793. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15794. }
  15795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15798. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15801. }
  15802. //2.4====================================== Voltage L1 ====================================================
  15803. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15804. {
  15805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15806. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15807. {
  15808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15809. {
  15810. tempIndex = ((gun_index==2) ? 1: 0);
  15811. }
  15812. else
  15813. {
  15814. tempIndex = gun_index;
  15815. }
  15816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15817. {
  15818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15819. {
  15820. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15821. }
  15822. } // END OF FOR CHAdeMO_QUANTITY
  15823. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15824. }
  15825. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15826. {
  15827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15828. {
  15829. tempIndex = ((gun_index==2) ? 1: 0);
  15830. }
  15831. else
  15832. {
  15833. tempIndex = gun_index;
  15834. }
  15835. for (int index = 0; index < CCS_QUANTITY; index++)
  15836. {
  15837. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15838. {
  15839. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15840. }
  15841. } // END OF FOR CCS_QUANTITY
  15842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15843. }
  15844. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15845. {
  15846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15847. {
  15848. tempIndex = ((gun_index==2) ? 1: 0);
  15849. }
  15850. else
  15851. {
  15852. tempIndex = gun_index;
  15853. }
  15854. for (int index = 0; index < GB_QUANTITY; index++)
  15855. {
  15856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15857. {
  15858. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15859. }
  15860. } // END OF FOR GB_QUANTITY
  15861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15862. }
  15863. else if(gunType[gun_index] == GUN_TYPE_DO)
  15864. {
  15865. tempIndex = gun_index;
  15866. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15867. {
  15868. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15869. {
  15870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15871. }
  15872. }
  15873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15874. }
  15875. else
  15876. {
  15877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15878. {
  15879. tempIndex = 2;
  15880. }
  15881. else
  15882. {
  15883. tempIndex = gun_index;
  15884. }
  15885. for (int index = 0; index < AC_QUANTITY; index++)
  15886. {
  15887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15888. {
  15889. 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
  15890. }
  15891. } // END OF FOR AC_QUANTITY
  15892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15893. }
  15894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15897. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15900. }
  15901. //2.5============================================== End SoC =========================================================
  15902. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15903. {
  15904. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15905. 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))
  15906. {
  15907. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15908. {
  15909. tempIndex = ((gun_index==2) ? 1: 0);
  15910. }
  15911. else
  15912. {
  15913. tempIndex = gun_index;
  15914. }
  15915. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15916. {
  15917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15918. {
  15919. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15920. {
  15921. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15922. }
  15923. }
  15924. }
  15925. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15926. {
  15927. for (int index = 0; index < CCS_QUANTITY; index++)
  15928. {
  15929. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15930. {
  15931. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15932. }
  15933. }
  15934. }
  15935. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15936. {
  15937. for (int index = 0; index < GB_QUANTITY; index++)
  15938. {
  15939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15940. {
  15941. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15942. }
  15943. }
  15944. }
  15945. else if(gunType[gun_index] == GUN_TYPE_DO)
  15946. {
  15947. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15948. {
  15949. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15950. {
  15951. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15952. }
  15953. }
  15954. }
  15955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15961. } // END FOR DC CASE
  15962. }
  15963. //2.6====================================== Current.Import L2 ==============================================
  15964. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15965. {
  15966. // AC 3 phase L2 current
  15967. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15968. {
  15969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15970. {
  15971. tempIndex = 2;
  15972. }
  15973. else
  15974. {
  15975. tempIndex = gun_index;
  15976. }
  15977. for (int index = 0; index < AC_QUANTITY; index++)
  15978. {
  15979. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15980. {
  15981. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15982. }
  15983. }// End of for AC_QUANTITY
  15984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15985. }
  15986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15989. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15990. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15991. }
  15992. //2.7====================================== Current.Import L3 ==============================================
  15993. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15994. {
  15995. // AC 3 phase L3 current
  15996. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15997. {
  15998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15999. {
  16000. tempIndex = 2;
  16001. }
  16002. else
  16003. {
  16004. tempIndex = gun_index;
  16005. }
  16006. for (int index = 0; index < AC_QUANTITY; index++)
  16007. {
  16008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16009. {
  16010. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16011. }
  16012. }// End of for AC_QUANTITY
  16013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16014. }
  16015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16020. }
  16021. //2.9====================================== Voltage L2 ====================================================
  16022. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16023. {
  16024. // AC 3 phase L2 volatge
  16025. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16026. {
  16027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16028. {
  16029. tempIndex = 2;
  16030. }
  16031. else
  16032. {
  16033. tempIndex = gun_index;
  16034. }
  16035. for (int index = 0; index < AC_QUANTITY; index++)
  16036. {
  16037. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16038. {
  16039. 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
  16040. }
  16041. } // END OF FOR AC_QUANTITY
  16042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16043. }
  16044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16045. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16047. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16048. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16049. }
  16050. //2.10====================================== Voltage L3 ====================================================
  16051. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16052. {
  16053. // AC 3 phase L3 volatge
  16054. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16055. {
  16056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16057. {
  16058. tempIndex = 2;
  16059. }
  16060. else
  16061. {
  16062. tempIndex = gun_index;
  16063. }
  16064. for (int index = 0; index < AC_QUANTITY; index++)
  16065. {
  16066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16067. {
  16068. 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
  16069. }
  16070. } // END OF FOR AC_QUANTITY
  16071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16072. }
  16073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16078. }
  16079. //====================== Start SoC ================================
  16080. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16081. {
  16082. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16083. 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))
  16084. {
  16085. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16086. {
  16087. tempIndex = ((gun_index==2) ? 1: 0);
  16088. }
  16089. else
  16090. {
  16091. tempIndex = gun_index;
  16092. }
  16093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16094. {
  16095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16096. {
  16097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16098. {
  16099. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16100. }
  16101. }
  16102. }
  16103. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16104. {
  16105. for (int index = 0; index < CCS_QUANTITY; index++)
  16106. {
  16107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16108. {
  16109. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16110. }
  16111. }
  16112. }
  16113. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16114. {
  16115. for (int index = 0; index < GB_QUANTITY; index++)
  16116. {
  16117. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16118. {
  16119. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16120. }
  16121. }
  16122. }
  16123. else if(gunType[gun_index] == GUN_TYPE_DO)
  16124. {
  16125. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16126. {
  16127. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16128. {
  16129. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16130. }
  16131. }
  16132. }
  16133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16137. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16139. } // END FOR DC CASE
  16140. }
  16141. //======================================== Message create ==============================================
  16142. json_object *StopTransaction = json_object_new_object();
  16143. json_object *transactionDatas = json_object_new_array();
  16144. json_object *sampledValues = json_object_new_array();
  16145. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16146. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16147. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16148. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16149. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16150. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16151. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16152. {
  16153. json_object *transactionData = json_object_new_object();
  16154. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16155. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16156. {
  16157. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16158. {
  16159. json_object *sampledValue = json_object_new_object();
  16160. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16161. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16162. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16163. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16164. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16165. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16166. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16167. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16168. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16169. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16170. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16171. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16172. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16173. json_object_array_add(sampledValues, sampledValue);
  16174. }
  16175. }
  16176. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16177. json_object_array_add(transactionDatas, transactionData);
  16178. }
  16179. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16180. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16181. ,MESSAGE_TYPE_CALL
  16182. ,guid
  16183. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16184. json_object_put(StopTransaction);
  16185. // Check File "TempStopTransaction" Exist
  16186. if((access(TempStopTransaction,F_OK))!=-1)
  16187. {
  16188. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16189. fclose(fopen(TempStopTransaction, "w"));
  16190. }
  16191. else
  16192. {
  16193. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16194. FILE *log = fopen(TempStopTransaction, "w+");
  16195. if(log == NULL)
  16196. {
  16197. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16198. return ;
  16199. }
  16200. else
  16201. {
  16202. fclose(log);
  16203. }
  16204. }
  16205. //Add TempStopTransaction | Update TempStopTransaction
  16206. // open file for writing
  16207. FILE *outfile;
  16208. outfile = fopen (TempStopTransaction, "a");
  16209. //DEBUG_INFO("data = %s\n", queuedata);
  16210. fputs(queuedata, outfile);
  16211. fputs("\n", outfile);
  16212. fclose (outfile);
  16213. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16214. }
  16215. void checkTempStopTransaction(int gun_index)
  16216. {
  16217. FILE *fptr1;
  16218. char ch;
  16219. char str[QUEUE_MESSAGE_LENGTH]={0};
  16220. char guid[37]={0};
  16221. char tempdata[65]={0};
  16222. char connectorStr[2]={0};
  16223. char TempStopTransaction[256];
  16224. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16225. fptr1 = fopen(TempStopTransaction, "r");
  16226. //TempStopTransaction格式: 槍號,StopTransaction封包
  16227. if (!fptr1)
  16228. {
  16229. //printf(" File not found or unable to open the input file!!\n");
  16230. return ;
  16231. }
  16232. ch=fgetc(fptr1);
  16233. //printf(" Now the content of the file %s is : \n",fname);
  16234. rewind(fptr1);
  16235. if(ch!=EOF)
  16236. {
  16237. // copy all contents to the temporary file except the specific line
  16238. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16239. {
  16240. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16241. if(str[0]=='\0')
  16242. {
  16243. break;
  16244. }
  16245. //TempStopTransaction格式: 槍號,StopTransaction封包
  16246. strncpy(connectorStr, str, 1);
  16247. if(atoi(connectorStr) != (gun_index+1))
  16248. {
  16249. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16250. fclose(fptr1);
  16251. return ;
  16252. }
  16253. //random_uuid(guid);
  16254. strncpy(guid, str+6, 36); //copy guid
  16255. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16256. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16257. {
  16258. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16259. }
  16260. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16261. OCPP_insert_transaction_msg(NO, str);
  16262. memset(str,0,ARRAY_SIZE(str));
  16263. }
  16264. }
  16265. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16266. fclose(fptr1);
  16267. remove(TempStopTransaction); // remove the original file
  16268. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16269. }
  16270. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16271. {
  16272. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16273. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16274. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16275. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16276. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16277. }
  16278. int GetWebSocketPingInterval(void)
  16279. {
  16280. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16281. }
  16282. int GetServerSign(void)
  16283. {
  16284. return server_sign;
  16285. }
  16286. uint8_t GetOcppSecurityProfile()
  16287. {
  16288. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16289. }
  16290. void GetOcppChargerBoxId(uint8_t *data)
  16291. {
  16292. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16293. }
  16294. void GetOcppSecurityPassword(uint8_t *data)
  16295. {
  16296. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16297. }
  16298. void SetOcppVersion(uint8_t *version)
  16299. {
  16300. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16301. DEBUG_INFO("ocpp version: %s\n", version);
  16302. if(strstr((char*)version, "ocpp1.6") != NULL)
  16303. {
  16304. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16305. }
  16306. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16307. {
  16308. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16309. system("pkill OcppBackend");
  16310. }
  16311. }
  16312. void SetServerSign(int value)
  16313. {
  16314. server_sign = value;
  16315. }
  16316. int GetBootNotificationInterval(void)
  16317. {
  16318. return BootNotificationInterval;
  16319. }
  16320. int GetInternetConn(void)
  16321. {
  16322. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16323. }
  16324. int GetBackendConnectionTimeout(void)
  16325. {
  16326. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16327. }
  16328. int isConnectorInitMode(int gun_index)
  16329. {
  16330. int tempIndex = 0;
  16331. int result = TRUE;
  16332. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16333. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16334. {
  16335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16336. {
  16337. tempIndex = ((gun_index==2) ? 1: 0);
  16338. }
  16339. else
  16340. {
  16341. tempIndex = gun_index;
  16342. }
  16343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16344. {
  16345. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16346. {
  16347. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16348. } //end of the same index
  16349. }//end of for CHAdeMO_QUANTITY
  16350. }
  16351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16352. {
  16353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16354. {
  16355. tempIndex = ((gun_index==2) ? 1: 0);
  16356. }
  16357. else
  16358. {
  16359. tempIndex = gun_index;
  16360. }
  16361. for (int index = 0; index < CCS_QUANTITY; index++)
  16362. {
  16363. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16364. {
  16365. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16366. } //end of the same index
  16367. } // end of for CCS_QUANTITY
  16368. }
  16369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16370. {
  16371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16372. {
  16373. tempIndex = ((gun_index==2) ? 1: 0);
  16374. }
  16375. else
  16376. {
  16377. tempIndex = gun_index;
  16378. }
  16379. for (int index = 0; index < GB_QUANTITY; index++)
  16380. {
  16381. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16382. {
  16383. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16384. } //end of the same index
  16385. } // end of for GB_QUANTITY
  16386. }
  16387. else if(gunType[gun_index] == GUN_TYPE_DO)
  16388. {
  16389. tempIndex = gun_index;
  16390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16391. {
  16392. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16393. {
  16394. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16395. } //end of the same index
  16396. }
  16397. }
  16398. else
  16399. {
  16400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16401. {
  16402. tempIndex = 2;
  16403. }
  16404. else
  16405. {
  16406. tempIndex = gun_index;
  16407. }
  16408. for (int index = 0; index < AC_QUANTITY; index++)
  16409. {
  16410. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16411. {
  16412. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16413. }//end of the same index
  16414. }//end of for AC_QUANTITY
  16415. }
  16416. return result;
  16417. }
  16418. void refreshProcDogTimer()
  16419. {
  16420. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16421. }
  16422. void InitialSystemValue(void)
  16423. {
  16424. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16425. gunTotalNumber=0;
  16426. SystemInitial = 0;
  16427. locallistVersion=0;
  16428. BootNotificationInterval = 0;
  16429. authorizeRetryTimes = 0;
  16430. GunStatusInterval = 10;
  16431. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16432. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16433. //Hear Beat
  16434. HeartBeatWithNOResponse = 0;
  16435. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16436. FirstHeartBeat = 0;
  16437. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16438. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16439. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16440. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16441. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16442. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16443. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16444. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16445. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16446. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16447. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16448. memset(gunType, 0, ARRAY_SIZE(gunType));
  16449. //Status && ConnectorPlugIn Setting
  16450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16451. {
  16452. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16453. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16454. }
  16455. for (int index = 0; index < CCS_QUANTITY; index++)
  16456. {
  16457. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16458. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16459. }
  16460. for (int index = 0; index < GB_QUANTITY; index++)
  16461. {
  16462. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16463. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16464. }
  16465. for (int index = 0; index < AC_QUANTITY; index++)
  16466. {
  16467. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16468. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16469. }
  16470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16471. {
  16472. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16473. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16474. }
  16475. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16476. {
  16477. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16478. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16479. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16480. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16481. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16482. }
  16483. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16484. clientTime.Heartbeat=time((time_t*)NULL);
  16485. sleep(1);
  16486. }
  16487. void LWS_Send(char *str)
  16488. {
  16489. //=====================================================
  16490. // Check InternetConn 0: disconnected, 1: connected
  16491. //====================================================
  16492. if(GetOcppConnStatus() == 0)
  16493. {
  16494. DEBUG_INFO("offline now !!!\n");
  16495. return;
  16496. }
  16497. // Only disable isWebsocketSendable operation initiated by charger
  16498. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16499. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16500. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16501. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16502. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16503. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16504. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16505. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16506. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16507. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16508. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16509. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16510. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16511. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16512. {
  16513. isWebsocketSendable = 0;
  16514. }
  16515. pthread_mutex_lock(&lock_send);
  16516. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16517. sprintf((char *)SendBuffer, "%s", str);
  16518. SendBufLen = strlen(str);
  16519. pthread_mutex_unlock(&lock_send);
  16520. lws_callback_on_writable(wsi_client);
  16521. //lws_service(context, 0);
  16522. //sleep(1);
  16523. }
  16524. void LWS_SendNow(char *str)
  16525. {
  16526. //=====================================================
  16527. // Check InternetConn 0: disconnected, 1: connected
  16528. //====================================================
  16529. if(GetOcppConnStatus() == 0)
  16530. {
  16531. DEBUG_INFO("offline now !!!\n");
  16532. return;
  16533. }
  16534. // Only disable isWebsocketSendable operation initiated by charger
  16535. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16536. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16537. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16538. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16539. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16540. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16541. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16542. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16543. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16544. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16545. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16546. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16547. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16548. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16549. {
  16550. isWebsocketSendable = 0;
  16551. }
  16552. pthread_mutex_lock(&lock_send);
  16553. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16554. sprintf((char *)SendBuffer, "%s", str);
  16555. SendBufLen = strlen(str);
  16556. pthread_mutex_unlock(&lock_send);
  16557. lws_callback_on_writable(wsi_client);
  16558. lws_service(context, 0);
  16559. //sleep(1);
  16560. }