MessageHandler.c 933 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  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 MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4.
  123. unsigned char :3; //bit 5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // Save configuration
  363. //=========================================
  364. int runShellCmd(const char*cmd)
  365. {
  366. int result = FAIL;
  367. char buf[256];
  368. FILE *fp;
  369. fp = popen(cmd, "r");
  370. if(fp != NULL)
  371. {
  372. while(fgets(buf, sizeof(buf), fp) != NULL)
  373. {
  374. DEBUG_INFO("%s\n", buf);
  375. }
  376. result = PASS;
  377. }
  378. pclose(fp);
  379. return result;
  380. }
  381. int StoreUsrConfigData(struct SysConfigData *UsrData)
  382. {
  383. int result = PASS;
  384. int fd,wrd;
  385. unsigned int i,Chk;
  386. unsigned char *ptr, *BufTmp;
  387. int MtdBlockSize = 0x300000;
  388. Chk=0;
  389. ptr=(unsigned char *)UsrData;
  390. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  391. {
  392. memset(BufTmp,0,MtdBlockSize);
  393. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  394. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  395. Chk+=*(BufTmp+i);
  396. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  397. // Output configuration to file.
  398. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  399. if (fd < 0)
  400. {
  401. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. wrd=write(fd, BufTmp, MtdBlockSize);
  406. close(fd);
  407. if(wrd<MtdBlockSize)
  408. {
  409. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  410. free(BufTmp);
  411. return 0;
  412. }
  413. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  414. DEBUG_INFO("Erase /dev/mtd10.\n");
  415. runShellCmd("flash_erase /dev/mtd10 0 0");
  416. DEBUG_INFO("Write /dev/mtd10.\n");
  417. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  418. DEBUG_INFO("Erase /dev/mtd11.\n");
  419. runShellCmd("flash_erase /dev/mtd11 0 0");
  420. DEBUG_INFO("Write /dev/mtd11.\n");
  421. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  422. system("rm -f /mnt/EvseConfig.bin");
  423. DEBUG_INFO("EvseConfig write to flash OK\n");
  424. }
  425. else
  426. {
  427. DEBUG_ERROR("alloc BlockSize NG\r\n");
  428. result = FAIL;
  429. }
  430. if(BufTmp!=NULL)
  431. free(BufTmp);
  432. return result;
  433. }
  434. //=========================================
  435. // Sqlite3 related function
  436. //=========================================
  437. static int selectSqlCount = 0;
  438. static int callback(void *data, int argc, char **argv, char **azColName){
  439. int i;
  440. //printf("%s: ", (const char*)data);
  441. selectSqlCount = argc;
  442. for(i = 0; i<argc; i++){
  443. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  444. }
  445. //printf("\n");
  446. return 0;
  447. }
  448. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  449. //int i;
  450. //printf("%s:\n", (const char*)data);
  451. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  452. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  453. return 0;
  454. }
  455. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  456. //printf("%s:\n", (const char*)data);
  457. //idTag
  458. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  459. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. //parentIdTag
  461. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  462. //expir_date
  463. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  464. //status
  465. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  466. //version
  467. if(columenCount > 5)
  468. idTagQuery.listVersionInt = atoi(columnValue[5]);
  469. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  470. return 0;
  471. }
  472. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  473. {
  474. // localversion = argv[5] ? atoi(argv[5]) : 0;
  475. // printf("localversion=%d\n", localversion);
  476. return 0;
  477. }
  478. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  479. {
  480. for (int i = 0; i < n_columns; i++)
  481. {
  482. DEBUG_INFO("%s\t", col_values[i]);
  483. }
  484. DEBUG_INFO("\n");
  485. return 0;
  486. }
  487. int OCPP_cleanLocalCache()
  488. {
  489. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  490. char *errMsg = 0;
  491. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  492. if (SQLITE_OK != rc)
  493. {
  494. DEBUG_INFO("SQL error: %s\n",errMsg);
  495. return FALSE;
  496. }
  497. return TRUE;
  498. }
  499. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  500. {
  501. int isSuccess = TRUE;
  502. int ret = 0;
  503. //const char* data = "Callback function called";
  504. char sql[300];
  505. char zErrMsg[200];
  506. memset(sql, 0, 300);
  507. memset(zErrMsg, 0, 200);
  508. 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);
  509. //* Execute SQL statement */
  510. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  511. if( ret != SQLITE_OK )
  512. {
  513. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  514. isSuccess = FALSE;
  515. }
  516. return isSuccess;
  517. }
  518. void OCPP_getIdTagFromLocalCache(char idTag[])
  519. {
  520. int rc = 0;
  521. char sql[100];
  522. char zErrMsg[100];
  523. memset(sql, 0, 100);
  524. memset(zErrMsg, 0, 100);
  525. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  526. memset(&idTagQuery, 0, sizeof(idTagQuery));
  527. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  528. /* Execute SQL statement */
  529. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  530. if( rc != SQLITE_OK )
  531. {
  532. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  533. }
  534. }
  535. void OCPP_getListVerion()
  536. {
  537. int rc = 0;
  538. // const char* data = "Callback function called";
  539. char sql[100];
  540. char zErrMsg[100];
  541. memset(sql, 0, 100);
  542. memset(zErrMsg, 0, 100);
  543. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  544. /* Execute SQL statement */
  545. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  546. if( rc != SQLITE_OK )
  547. {
  548. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  549. }
  550. }
  551. void OCPP_get_TableAuthlocalAllData(void)
  552. {
  553. int rc = 0;
  554. char sql[100];
  555. char zErrMsg[100];
  556. memset(sql, 0, 100);
  557. memset(zErrMsg, 0, 100);
  558. sprintf(sql,"select * from ocpp_auth_local ");
  559. /* Execute SQL statement */
  560. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  561. if( rc != SQLITE_OK )
  562. {
  563. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  564. }
  565. //return ver;
  566. }
  567. int OCPP_cleanLocalList()
  568. {
  569. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  570. char *errMsg = 0;
  571. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  572. if (SQLITE_OK != rc)
  573. {
  574. DEBUG_INFO("%s\n",errMsg);
  575. return FALSE;
  576. }
  577. return TRUE;
  578. }
  579. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  580. {
  581. int isSuccess = FALSE;
  582. int ret = 0;
  583. //const char* data = "Callback function called";
  584. char sql[300];
  585. char zErrMsg[200];
  586. memset(sql, 0, 300);
  587. memset(zErrMsg, 0, 200);
  588. 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);
  589. //* Execute SQL statement */
  590. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. memset(sql, 0, 300);
  597. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  598. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  599. if( ret != SQLITE_OK )
  600. {
  601. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  602. return isSuccess;
  603. }
  604. isSuccess = TRUE;
  605. return isSuccess;
  606. }
  607. void OCPP_getIdTagFromLocalList(char idTag[])
  608. {
  609. int rc = 0;
  610. // const char* data = "Callback function called";
  611. char sql[100];
  612. char zErrMsg[100];
  613. memset(sql, 0, 100);
  614. memset(zErrMsg, 0, 100);
  615. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  616. memset(&idTagQuery, 0, sizeof(idTagQuery));
  617. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  618. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  619. /* Execute SQL statement */
  620. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  621. if( rc != SQLITE_OK )
  622. {
  623. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  624. }
  625. //return ver;
  626. }
  627. void OCPP_deleteIdTagFromLocalList(char idTag[])
  628. {
  629. //int ver = 0;
  630. //int isSuccess = FALSE;
  631. int rc = 0;
  632. char sql[100];
  633. char zErrMsg[100];
  634. memset(sql, 0, 100);
  635. memset(zErrMsg, 0, 100);
  636. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  637. //* Execute SQL statement */
  638. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  639. if( rc != SQLITE_OK )
  640. {
  641. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  642. }
  643. }
  644. int getCurrentYear()
  645. {
  646. int result = 0;
  647. time_t CurrentTime;
  648. struct tm *tm;
  649. CurrentTime = time(NULL);
  650. tm=localtime(&CurrentTime);
  651. result = (tm->tm_year + 1900);
  652. return result;
  653. }
  654. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  655. {
  656. int result = PASS;
  657. char* errMsg = NULL;
  658. char sqlStr[8192];
  659. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  664. }
  665. 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));
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  670. }
  671. return result;
  672. }
  673. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  674. {
  675. int result = PASS;
  676. char* errMsg = NULL;
  677. char sqlStr[8192];
  678. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  679. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  680. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  681. {
  682. result = FAIL;
  683. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  684. }
  685. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. return result;
  692. }
  693. int OCPP_update_deduct_info(int txId, char *creditNo)
  694. {
  695. int result = PASS;
  696. char* errMsg = NULL;
  697. char sqlStr[8192];
  698. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  699. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  700. {
  701. result = FAIL;
  702. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  703. }
  704. return result;
  705. }
  706. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  707. {
  708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  711. atoi(columnValue[1]),
  712. columnValue[2],
  713. atoi(columnValue[3])==1?"true":"false",
  714. atoi(columnValue[4])==1?"true":"false",
  715. columnValue[5],
  716. columnValue[9]);
  717. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  718. return 0;
  719. }
  720. void OCPP_query_deduct_info()
  721. {
  722. int rc = 0;
  723. char sql[100];
  724. char zErrMsg[100];
  725. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  726. /* Execute SQL statement */
  727. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  728. if( rc != SQLITE_OK )
  729. {
  730. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  731. }
  732. }
  733. void reportReaderStatus(int gun_index)
  734. {
  735. struct timeval tmnow;
  736. struct tm *tm;
  737. char buf[28];//, usec_buf[6];
  738. gettimeofday(&tmnow, NULL);
  739. time_t t;
  740. t = time(NULL);
  741. /*UTC time and date*/
  742. tm = gmtime(&t);
  743. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  744. #if 0 // remove temporally
  745. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  746. strcat(buf,".");
  747. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  748. strcat(buf,usec_buf);
  749. #endif
  750. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  753. (gun_index+1),
  754. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  755. buf,
  756. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  757. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  758. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  759. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  760. }
  761. //==========================================
  762. // Check time passed since today
  763. //==========================================
  764. long long DiffTimebWithNow(struct timeb ST)
  765. {
  766. //return milli-second
  767. struct timeb ET;
  768. long long StartTime,StopTime;
  769. ftime(&ET);
  770. StartTime=(long long)ST.time;
  771. StopTime=(long long)ET.time;
  772. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  773. }
  774. int getTimePassSinceToday(uint8_t gun_index)
  775. {
  776. int result = -1;
  777. static time_t lastTime[4];
  778. time_t t;
  779. struct tm *tmStartToday;
  780. struct timeb tbStartToday;
  781. t=time(NULL);
  782. if(difftime(t, lastTime[gun_index])>0)
  783. {
  784. tmStartToday=localtime(&t);
  785. tmStartToday->tm_hour = 0;
  786. tmStartToday->tm_min = 0;
  787. tmStartToday->tm_sec = 0;
  788. tbStartToday.time = mktime(tmStartToday);
  789. tbStartToday.millitm = 0;
  790. result = DiffTimebWithNow(tbStartToday)/1000;
  791. lastTime[gun_index] = t;
  792. }
  793. return result;
  794. }
  795. void getNowDatetime(uint8_t *data)
  796. {
  797. time_t t = time(NULL);
  798. struct tm tm = *localtime(&t);
  799. 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);
  800. }
  801. int syncDateTimeRTC(uint8_t *data)
  802. {
  803. struct ParsingResult
  804. {
  805. int result;
  806. int scanedElement;
  807. int year;
  808. int month;
  809. int mday;
  810. int hour;
  811. int min;
  812. int sec;
  813. int tz_hour;
  814. int tz_min;
  815. float minSec;
  816. }result;
  817. struct tm tmOrg;
  818. struct tm *tmTarget;
  819. struct timeb tbTarget;
  820. char buf[128];
  821. memset(&result, 0x00, sizeof(struct ParsingResult));
  822. result.result = PASS;
  823. if(strstr((char*)data, ".") != NULL)
  824. {
  825. // Original data with mini second
  826. if(strstr((char*)data, "Z") != NULL)
  827. {
  828. // Original data with Z
  829. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  830. &result.year,
  831. &result.month,
  832. &result.mday,
  833. &result.hour,
  834. &result.min,
  835. &result.sec,
  836. &result.minSec);
  837. }
  838. else
  839. {
  840. // Original data without Z
  841. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  842. &result.year,
  843. &result.month,
  844. &result.mday,
  845. &result.hour,
  846. &result.min,
  847. &result.sec,
  848. &result.minSec,
  849. &result.tz_hour,
  850. &result.tz_min);
  851. }
  852. }
  853. else
  854. {
  855. // Original data without mini second
  856. if(strstr((char*)data, "Z") != NULL)
  857. {
  858. // Original data with Z
  859. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  860. &result.year,
  861. &result.month,
  862. &result.mday,
  863. &result.hour,
  864. &result.min,
  865. &result.sec);
  866. }
  867. else
  868. {
  869. // Original data without Z
  870. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  871. &result.year,
  872. &result.month,
  873. &result.mday,
  874. &result.hour,
  875. &result.min,
  876. &result.sec,
  877. &result.tz_hour,
  878. &result.tz_min);
  879. }
  880. }
  881. tmOrg.tm_year = result.year - 1900;
  882. tmOrg.tm_mon = result.month - 1;
  883. tmOrg.tm_mday = result.mday;
  884. tmOrg.tm_hour = result.hour;
  885. tmOrg.tm_min = result.min;
  886. tmOrg.tm_sec = result.sec;
  887. tmOrg.tm_gmtoff = 0;
  888. tbTarget.time = mktime(&tmOrg);
  889. tbTarget.timezone = 0;
  890. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  891. tmTarget = gmtime(&tbTarget.time);
  892. 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);
  893. //DEBUG_INFO(" org date time: %s\n", data);
  894. //DEBUG_INFO("parse date time: %s\n", buf);
  895. system(buf);
  896. system("/sbin/hwclock -w --systohc");
  897. if(result.scanedElement < 6)
  898. result.result = FAIL;
  899. return result.result;
  900. }
  901. //==========================================
  902. // GetCompositeSchedule logic related function
  903. //==========================================
  904. int DiffTimebSec(struct timeb ST, struct timeb ET)
  905. {
  906. //return milli-second
  907. unsigned int StartTime,StopTime;
  908. StartTime=(unsigned int)ST.time;
  909. StopTime=(unsigned int)ET.time;
  910. return (StopTime-StartTime);
  911. }
  912. int DiffTimebWithNowSec(struct timeb ST)
  913. {
  914. //return milli-second
  915. struct timeb ET;
  916. unsigned int StartTime,StopTime;
  917. ftime(&ET);
  918. StartTime=(unsigned int)ST.time;
  919. StopTime=(unsigned int)ET.time;
  920. return (StopTime-StartTime);
  921. }
  922. int getStartStop(uint8_t *start, uint8_t *stop)
  923. {
  924. struct ParsingResult
  925. {
  926. int result;
  927. int scanedElement;
  928. int year;
  929. int month;
  930. int mday;
  931. int hour;
  932. int min;
  933. int sec;
  934. int tz_hour;
  935. int tz_min;
  936. float minSec;
  937. };
  938. struct ParsingResult parseStart;
  939. struct ParsingResult parseStop;
  940. int result = -1;
  941. struct tm tmStart;
  942. struct timeb tbStart;
  943. struct tm tmStop;
  944. struct timeb tbStop;
  945. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  946. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  947. // Scan start & stop date time
  948. if(strstr((char*)start, ".") != NULL)
  949. {
  950. // Original data with mini second
  951. if(strstr((char*)start, "Z") != NULL)
  952. {
  953. // Original data with Z
  954. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  955. &parseStart.year,
  956. &parseStart.month,
  957. &parseStart.mday,
  958. &parseStart.hour,
  959. &parseStart.min,
  960. &parseStart.sec,
  961. &parseStart.minSec);
  962. }
  963. else
  964. {
  965. // Original data without Z
  966. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  967. &parseStart.year,
  968. &parseStart.month,
  969. &parseStart.mday,
  970. &parseStart.hour,
  971. &parseStart.min,
  972. &parseStart.sec,
  973. &parseStart.minSec,
  974. &parseStart.tz_hour,
  975. &parseStart.tz_min);
  976. }
  977. }
  978. else
  979. {
  980. // Original data without mini second
  981. if(strstr((char*)start, "Z") != NULL)
  982. {
  983. // Original data with Z
  984. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  985. &parseStart.year,
  986. &parseStart.month,
  987. &parseStart.mday,
  988. &parseStart.hour,
  989. &parseStart.min,
  990. &parseStart.sec);
  991. }
  992. else
  993. {
  994. // Original data without Z
  995. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  996. &parseStart.year,
  997. &parseStart.month,
  998. &parseStart.mday,
  999. &parseStart.hour,
  1000. &parseStart.min,
  1001. &parseStart.sec,
  1002. &parseStart.tz_hour,
  1003. &parseStart.tz_min);
  1004. }
  1005. }
  1006. if(strstr((char*)stop, ".") != NULL)
  1007. {
  1008. // Original data with mini second
  1009. if(strstr((char*)stop, "Z") != NULL)
  1010. {
  1011. // Original data with Z
  1012. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1013. &parseStop.year,
  1014. &parseStop.month,
  1015. &parseStop.mday,
  1016. &parseStop.hour,
  1017. &parseStop.min,
  1018. &parseStop.sec,
  1019. &parseStop.minSec);
  1020. }
  1021. else
  1022. {
  1023. // Original data without Z
  1024. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1025. &parseStop.year,
  1026. &parseStop.month,
  1027. &parseStop.mday,
  1028. &parseStop.hour,
  1029. &parseStop.min,
  1030. &parseStop.sec,
  1031. &parseStop.minSec,
  1032. &parseStop.tz_hour,
  1033. &parseStop.tz_min);
  1034. }
  1035. }
  1036. else
  1037. {
  1038. // Original data without mini second
  1039. if(strstr((char*)stop, "Z") != NULL)
  1040. {
  1041. // Original data with Z
  1042. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1043. &parseStop.year,
  1044. &parseStop.month,
  1045. &parseStop.mday,
  1046. &parseStop.hour,
  1047. &parseStop.min,
  1048. &parseStop.sec);
  1049. }
  1050. else
  1051. {
  1052. // Original data without Z
  1053. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1054. &parseStop.year,
  1055. &parseStop.month,
  1056. &parseStop.mday,
  1057. &parseStop.hour,
  1058. &parseStop.min,
  1059. &parseStop.sec,
  1060. &parseStop.tz_hour,
  1061. &parseStop.tz_min);
  1062. }
  1063. }
  1064. // Calculate date time difference
  1065. if((parseStart.scanedElement >=6) &&
  1066. (parseStop.scanedElement >=6))
  1067. {
  1068. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1069. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1070. tmStart.tm_year = parseStart.year - 1900;
  1071. tmStart.tm_mon = parseStart.month - 1;
  1072. tmStart.tm_mday = parseStart.mday;
  1073. tmStart.tm_hour = parseStart.hour;
  1074. tmStart.tm_min = parseStart.min;
  1075. tmStart.tm_sec = parseStart.sec;
  1076. tmStart.tm_gmtoff = 0;
  1077. tbStart.time = mktime(&tmStart);
  1078. tbStart.timezone = 0;
  1079. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1080. tmStop.tm_year = parseStop.year - 1900;
  1081. tmStop.tm_mon = parseStop.month - 1;
  1082. tmStop.tm_mday = parseStop.mday;
  1083. tmStop.tm_hour = parseStop.hour;
  1084. tmStop.tm_min = parseStop.min;
  1085. tmStop.tm_sec = parseStop.sec;
  1086. tmStop.tm_gmtoff = 0;
  1087. tbStop.time = mktime(&tmStop);
  1088. tbStop.timezone = 0;
  1089. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1090. result = DiffTimebSec(tbStart, tbStop);
  1091. //DEBUG_INFO("getStartStop(): %d\n", result);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1096. }
  1097. return result;
  1098. }
  1099. int isOvertNow(uint8_t *start)
  1100. {
  1101. int result = NO;
  1102. struct ParsingResult
  1103. {
  1104. int result;
  1105. int scanedElement;
  1106. int year;
  1107. int month;
  1108. int mday;
  1109. int hour;
  1110. int min;
  1111. int sec;
  1112. int tz_hour;
  1113. int tz_min;
  1114. float minSec;
  1115. }parsingResult;
  1116. struct tm tmStart;
  1117. struct timeb tbStart;
  1118. if(strstr((char*)start, ".") != NULL)
  1119. {
  1120. // Original data with mini second
  1121. if(strstr((char*)start, "Z") != NULL)
  1122. {
  1123. // Original data with Z
  1124. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1125. &parsingResult.year,
  1126. &parsingResult.month,
  1127. &parsingResult.mday,
  1128. &parsingResult.hour,
  1129. &parsingResult.min,
  1130. &parsingResult.sec,
  1131. &parsingResult.minSec);
  1132. }
  1133. else
  1134. {
  1135. // Original data without Z
  1136. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1137. &parsingResult.year,
  1138. &parsingResult.month,
  1139. &parsingResult.mday,
  1140. &parsingResult.hour,
  1141. &parsingResult.min,
  1142. &parsingResult.sec,
  1143. &parsingResult.minSec,
  1144. &parsingResult.tz_hour,
  1145. &parsingResult.tz_min);
  1146. }
  1147. }
  1148. else
  1149. {
  1150. // Original data without mini second
  1151. if(strstr((char*)start, "Z") != NULL)
  1152. {
  1153. // Original data with Z
  1154. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1155. &parsingResult.year,
  1156. &parsingResult.month,
  1157. &parsingResult.mday,
  1158. &parsingResult.hour,
  1159. &parsingResult.min,
  1160. &parsingResult.sec);
  1161. }
  1162. else
  1163. {
  1164. // Original data without Z
  1165. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1166. &parsingResult.year,
  1167. &parsingResult.month,
  1168. &parsingResult.mday,
  1169. &parsingResult.hour,
  1170. &parsingResult.min,
  1171. &parsingResult.sec,
  1172. &parsingResult.tz_hour,
  1173. &parsingResult.tz_min);
  1174. }
  1175. }
  1176. if(parsingResult.scanedElement >= 6)
  1177. {
  1178. tmStart.tm_year = parsingResult.year - 1900;
  1179. tmStart.tm_mon = parsingResult.month - 1;
  1180. tmStart.tm_mday = parsingResult.mday;
  1181. tmStart.tm_hour = parsingResult.hour;
  1182. tmStart.tm_min = parsingResult.min;
  1183. tmStart.tm_sec = parsingResult.sec;
  1184. tmStart.tm_gmtoff = 0;
  1185. tbStart.time = mktime(&tmStart);
  1186. tbStart.timezone = 0;
  1187. tbStart.millitm = 0;
  1188. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1189. if(DiffTimebWithNowSec(tbStart) <= 0)
  1190. result = NO;
  1191. else
  1192. result = YES;
  1193. }
  1194. else
  1195. {
  1196. DEBUG_WARN("Start date parsing error.\n");
  1197. }
  1198. return result;
  1199. }
  1200. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1201. {
  1202. struct ParsingResult
  1203. {
  1204. int result;
  1205. int scanedElement;
  1206. int year;
  1207. int month;
  1208. int mday;
  1209. int hour;
  1210. int min;
  1211. int sec;
  1212. int tz_hour;
  1213. int tz_min;
  1214. float minSec;
  1215. };
  1216. struct ParsingResult parseStart;
  1217. struct ParsingResult parseStop;
  1218. int result = -1;
  1219. struct tm tmStart;
  1220. struct timeb tbStart;
  1221. struct tm tmStop;
  1222. struct timeb tbStop;
  1223. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1224. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1225. // Scan start & stop date time
  1226. if(strstr((char*)start, ".") != NULL)
  1227. {
  1228. // Original data with mini second
  1229. if(strstr((char*)start, "Z") != NULL)
  1230. {
  1231. // Original data with Z
  1232. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1233. &parseStart.year,
  1234. &parseStart.month,
  1235. &parseStart.mday,
  1236. &parseStart.hour,
  1237. &parseStart.min,
  1238. &parseStart.sec,
  1239. &parseStart.minSec);
  1240. }
  1241. else
  1242. {
  1243. // Original data without Z
  1244. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1245. &parseStart.year,
  1246. &parseStart.month,
  1247. &parseStart.mday,
  1248. &parseStart.hour,
  1249. &parseStart.min,
  1250. &parseStart.sec,
  1251. &parseStart.minSec,
  1252. &parseStart.tz_hour,
  1253. &parseStart.tz_min);
  1254. }
  1255. }
  1256. else
  1257. {
  1258. // Original data without mini second
  1259. if(strstr((char*)start, "Z") != NULL)
  1260. {
  1261. // Original data with Z
  1262. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1263. &parseStart.year,
  1264. &parseStart.month,
  1265. &parseStart.mday,
  1266. &parseStart.hour,
  1267. &parseStart.min,
  1268. &parseStart.sec);
  1269. }
  1270. else
  1271. {
  1272. // Original data without Z
  1273. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1274. &parseStart.year,
  1275. &parseStart.month,
  1276. &parseStart.mday,
  1277. &parseStart.hour,
  1278. &parseStart.min,
  1279. &parseStart.sec,
  1280. &parseStart.tz_hour,
  1281. &parseStart.tz_min);
  1282. }
  1283. }
  1284. if(strstr((char*)stop, ".") != NULL)
  1285. {
  1286. // Original data with mini second
  1287. if(strstr((char*)stop, "Z") != NULL)
  1288. {
  1289. // Original data with Z
  1290. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1291. &parseStop.year,
  1292. &parseStop.month,
  1293. &parseStop.mday,
  1294. &parseStop.hour,
  1295. &parseStop.min,
  1296. &parseStop.sec,
  1297. &parseStop.minSec);
  1298. }
  1299. else
  1300. {
  1301. // Original data without Z
  1302. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1303. &parseStop.year,
  1304. &parseStop.month,
  1305. &parseStop.mday,
  1306. &parseStop.hour,
  1307. &parseStop.min,
  1308. &parseStop.sec,
  1309. &parseStop.minSec,
  1310. &parseStop.tz_hour,
  1311. &parseStop.tz_min);
  1312. }
  1313. }
  1314. else
  1315. {
  1316. // Original data without mini second
  1317. if(strstr((char*)stop, "Z") != NULL)
  1318. {
  1319. // Original data with Z
  1320. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1321. &parseStop.year,
  1322. &parseStop.month,
  1323. &parseStop.mday,
  1324. &parseStop.hour,
  1325. &parseStop.min,
  1326. &parseStop.sec);
  1327. }
  1328. else
  1329. {
  1330. // Original data without Z
  1331. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1332. &parseStop.year,
  1333. &parseStop.month,
  1334. &parseStop.mday,
  1335. &parseStop.hour,
  1336. &parseStop.min,
  1337. &parseStop.sec,
  1338. &parseStop.tz_hour,
  1339. &parseStop.tz_min);
  1340. }
  1341. }
  1342. // Calculate date time difference
  1343. if((parseStart.scanedElement >=6) &&
  1344. (parseStop.scanedElement >=6))
  1345. {
  1346. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1347. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1348. tmStart.tm_year = parseStart.year - 1900;
  1349. tmStart.tm_mon = parseStart.month - 1;
  1350. tmStart.tm_mday = parseStart.mday;
  1351. tmStart.tm_hour = parseStart.hour;
  1352. tmStart.tm_min = parseStart.min;
  1353. tmStart.tm_sec = parseStart.sec;
  1354. tmStart.tm_gmtoff = 0;
  1355. tbStart.time = mktime(&tmStart);
  1356. tbStart.timezone = 0;
  1357. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1358. tmStop.tm_year = parseStop.year - 1900;
  1359. tmStop.tm_mon = parseStop.month - 1;
  1360. tmStop.tm_mday = parseStop.mday;
  1361. tmStop.tm_hour = parseStop.hour;
  1362. tmStop.tm_min = parseStop.min;
  1363. tmStop.tm_sec = parseStop.sec;
  1364. tmStop.tm_gmtoff = 0;
  1365. tbStop.time = mktime(&tmStop);
  1366. tbStop.timezone = 0;
  1367. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1368. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1369. //DEBUG_INFO("getStartStop(): %d\n", result);
  1370. }
  1371. else
  1372. {
  1373. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1374. }
  1375. return result;
  1376. }
  1377. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1378. {
  1379. FILE *fp;
  1380. char profileFileName[128];
  1381. char *line = NULL;
  1382. size_t len = 0;
  1383. time_t CurrentTime;
  1384. struct tm *tmComposite;
  1385. struct StructChargingProfile maxProfile;
  1386. struct StructChargingProfile compositeProfile;
  1387. uint8_t limitMax=0;
  1388. int compositePeriodIdx = 0;
  1389. CurrentTime = time(NULL);
  1390. tmComposite=localtime(&CurrentTime);
  1391. 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);
  1392. if(isUnitA)
  1393. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1394. else
  1395. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1396. compositeProfile.ChargingSchedule.Duration = durationReq;
  1397. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1398. {
  1399. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1402. }
  1403. compositeProfile.ChargingProfileId = 0;
  1404. compositeProfile.StackLevel = 99 ;
  1405. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.ChargingSchedule.Duration = -1;
  1408. system("rm -f /tmp/*.json");
  1409. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1410. // Search max profile
  1411. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1412. if((access(profileFileName, F_OK))!=-1)
  1413. {
  1414. fp = fopen(profileFileName, "r");
  1415. while(getline(&line, &len, fp) != -1)
  1416. {
  1417. json_object *obj = NULL;
  1418. obj = json_tokener_parse(line);
  1419. if(is_error(obj))
  1420. {
  1421. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1422. }
  1423. else
  1424. {
  1425. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1426. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1427. )
  1428. {
  1429. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1430. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1431. )
  1432. {
  1433. struct tm tmFrom, tmTo;
  1434. struct timeb tbFrom, tbTo;
  1435. 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) &&
  1436. (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))
  1437. {
  1438. tmFrom.tm_year -= 1900;
  1439. tmFrom.tm_mon -= 1;
  1440. tbFrom.time = mktime(&tmFrom);
  1441. tmTo.tm_year -= 1900;
  1442. tmTo.tm_mon -= 1;
  1443. tbTo.time = mktime(&tmTo);
  1444. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1445. {
  1446. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1447. {
  1448. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1451. }
  1452. if(maxProfile.ChargingProfileId == -1)
  1453. DEBUG_INFO("MaxProfile found.\n");
  1454. else
  1455. DEBUG_INFO("MaxProfile updated.\n");
  1456. // Required item
  1457. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1458. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1459. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1460. if(isUnitA)
  1461. {
  1462. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1463. 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++)
  1464. {
  1465. 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"));
  1466. 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?
  1467. 3:
  1468. 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")));
  1469. 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")));
  1470. }
  1471. }
  1472. else
  1473. {
  1474. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1475. 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++)
  1476. {
  1477. 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"));
  1478. 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?
  1479. 3:
  1480. 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")));
  1481. 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));
  1482. }
  1483. }
  1484. // Optional item
  1485. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1486. {
  1487. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1488. }
  1489. else
  1490. {
  1491. sprintf((char*)maxProfile.ValidFrom, " ");
  1492. }
  1493. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1494. {
  1495. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1496. }
  1497. else
  1498. {
  1499. sprintf((char*)maxProfile.ValidTo, " ");
  1500. }
  1501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1502. {
  1503. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1504. }
  1505. else
  1506. {
  1507. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1508. }
  1509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1510. {
  1511. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1512. }
  1513. else
  1514. {
  1515. maxProfile.TransactionId = -1;
  1516. }
  1517. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1518. {
  1519. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1520. }
  1521. else
  1522. {
  1523. maxProfile.ChargingSchedule.Duration = 86400;
  1524. }
  1525. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1526. {
  1527. 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")));
  1528. }
  1529. else
  1530. {
  1531. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1532. }
  1533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1534. {
  1535. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1536. }
  1537. else
  1538. {
  1539. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1540. }
  1541. }
  1542. }
  1543. }
  1544. else
  1545. {
  1546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1547. {
  1548. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1551. }
  1552. if(maxProfile.ChargingProfileId == -1)
  1553. DEBUG_INFO("MaxProfile found.\n");
  1554. else
  1555. DEBUG_INFO("MaxProfile updated.\n");
  1556. // Required item
  1557. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1558. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1559. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1560. if(isUnitA)
  1561. {
  1562. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1563. 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++)
  1564. {
  1565. 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"));
  1566. 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?
  1567. 3:
  1568. 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")));
  1569. 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")));
  1570. }
  1571. }
  1572. else
  1573. {
  1574. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1575. 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++)
  1576. {
  1577. 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"));
  1578. 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?
  1579. 3:
  1580. 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")));
  1581. 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));
  1582. }
  1583. }
  1584. // Optional item
  1585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1586. {
  1587. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)maxProfile.ValidFrom, " ");
  1592. }
  1593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1594. {
  1595. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1596. }
  1597. else
  1598. {
  1599. sprintf((char*)maxProfile.ValidTo, " ");
  1600. }
  1601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1602. {
  1603. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1604. }
  1605. else
  1606. {
  1607. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1608. }
  1609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1610. {
  1611. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1612. }
  1613. else
  1614. {
  1615. maxProfile.TransactionId = -1;
  1616. }
  1617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1618. {
  1619. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1620. }
  1621. else
  1622. {
  1623. maxProfile.ChargingSchedule.Duration = 86400;
  1624. }
  1625. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1626. {
  1627. 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")));
  1628. }
  1629. else
  1630. {
  1631. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1632. }
  1633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1634. {
  1635. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1636. }
  1637. else
  1638. {
  1639. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. json_object_put(obj);
  1645. }
  1646. fclose(fp);
  1647. /*
  1648. if(maxProfile.ChargingProfileId !=-1)
  1649. {
  1650. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1651. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1652. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1653. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1654. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1655. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1656. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1657. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1658. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1659. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1660. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1661. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1662. {
  1663. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1664. {
  1665. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1666. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1667. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1668. }
  1669. }
  1670. }
  1671. else
  1672. DEBUG_INFO("MaxProfile not found.\n");
  1673. DEBUG_INFO("------------------------------------\n");*/
  1674. }
  1675. if(maxProfile.ChargingProfileId != -1)
  1676. {
  1677. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1678. {
  1679. if(maxProfile.ChargingSchedule.Duration != -1)
  1680. {
  1681. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1682. 0:
  1683. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1684. }
  1685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1686. {
  1687. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1688. {
  1689. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1690. 0:
  1691. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1692. if(idxPeriod > 0)
  1693. {
  1694. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1695. {
  1696. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1703. {
  1704. if(maxProfile.ChargingSchedule.Duration != -1)
  1705. {
  1706. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1707. }
  1708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1709. {
  1710. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1711. {
  1712. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1713. if(idxPeriod > 0)
  1714. {
  1715. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1716. {
  1717. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1718. }
  1719. }
  1720. }
  1721. }
  1722. }
  1723. else
  1724. {
  1725. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1726. {
  1727. if(maxProfile.ChargingSchedule.Duration != -1)
  1728. {
  1729. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1730. 0:
  1731. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1732. }
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1736. {
  1737. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1738. 0:
  1739. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1740. if(idxPeriod > 0)
  1741. {
  1742. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1743. {
  1744. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if(maxProfile.ChargingSchedule.Duration != -1)
  1753. {
  1754. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1755. 0:
  1756. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1757. }
  1758. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1759. {
  1760. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1761. {
  1762. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1763. 0:
  1764. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1765. if(idxPeriod > 0)
  1766. {
  1767. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1768. {
  1769. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. /*
  1777. DEBUG_INFO("MaxProfile after align.\n");
  1778. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1779. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1780. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1781. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1782. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1783. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1784. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1785. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1786. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1787. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1788. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1789. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1790. {
  1791. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1792. {
  1793. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1794. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1795. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1796. }
  1797. }
  1798. DEBUG_INFO("------------------------------------\n");*/
  1799. }
  1800. // Find each profile period quantity
  1801. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1802. {
  1803. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1804. limitMax = idx+1;
  1805. }
  1806. if(maxProfile.ChargingProfileId != -1)
  1807. {
  1808. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1809. {
  1810. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1811. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1812. (maxProfile.ChargingSchedule.Duration > 0))
  1813. {
  1814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1815. {
  1816. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1817. compositePeriodIdx++;
  1818. }
  1819. else
  1820. {
  1821. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. }
  1823. }
  1824. }
  1825. }
  1826. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1827. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1828. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1829. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1830. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1831. {
  1832. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1833. {
  1834. compositeProfile.ChargingProfileId = 1;
  1835. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1836. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1837. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1838. }
  1839. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1840. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1841. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1842. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1843. }
  1844. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1845. if(line)
  1846. free(line);
  1847. }
  1848. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1849. {
  1850. FILE *fp;
  1851. char profileFileName[128];
  1852. char *line = NULL;
  1853. size_t len = 0;
  1854. time_t CurrentTime;
  1855. struct tm *tmComposite;
  1856. struct StructChargingProfile maxProfile;
  1857. struct StructChargingProfile defaultTxProfile;
  1858. struct StructChargingProfile txProfile;
  1859. struct StructChargingProfile compositeProfile;
  1860. struct StructChargingSchedulePeriod tmpPeriod;
  1861. uint8_t limitMax=0;
  1862. uint8_t limitDef=0;
  1863. uint8_t limitTx=0;
  1864. int compositePeriodIdx = 0;
  1865. CurrentTime = time(NULL);
  1866. tmComposite=localtime(&CurrentTime);
  1867. 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);
  1868. if(isUnitA)
  1869. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1870. else
  1871. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1872. compositeProfile.ChargingSchedule.Duration = durationReq;
  1873. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1874. {
  1875. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1878. }
  1879. compositeProfile.ChargingProfileId = 0;
  1880. compositeProfile.StackLevel = 99 ;
  1881. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1882. maxProfile.ChargingProfileId = -1;
  1883. defaultTxProfile.ChargingProfileId = -1;
  1884. txProfile.ChargingProfileId = -1;
  1885. maxProfile.ChargingSchedule.Duration = -1;
  1886. defaultTxProfile.ChargingSchedule.Duration = -1;
  1887. txProfile.ChargingSchedule.Duration = -1;
  1888. system("rm -f /tmp/*.json");
  1889. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1890. /*
  1891. * Search valid charging profile
  1892. */
  1893. //DEBUG_INFO("====================================\n");
  1894. // Search tx profile
  1895. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1896. if((access(profileFileName, F_OK))!=-1)
  1897. {
  1898. fp = fopen(profileFileName, "r");
  1899. while(getline(&line, &len, fp) != -1)
  1900. {
  1901. json_object *obj = NULL;
  1902. obj = json_tokener_parse(line);
  1903. if(is_error(obj))
  1904. {
  1905. DEBUG_ERROR("Parse txProfile from file error.\n");
  1906. }
  1907. else
  1908. {
  1909. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1910. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1911. )
  1912. {
  1913. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1914. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1915. )
  1916. {
  1917. struct tm tmFrom, tmTo;
  1918. struct timeb tbFrom, tbTo;
  1919. 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) &&
  1920. (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))
  1921. {
  1922. tmFrom.tm_year -= 1900;
  1923. tmFrom.tm_mon -= 1;
  1924. tbFrom.time = mktime(&tmFrom);
  1925. tmTo.tm_year -= 1900;
  1926. tmTo.tm_mon -= 1;
  1927. tbTo.time = mktime(&tmTo);
  1928. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1929. {
  1930. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1931. {
  1932. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1935. }
  1936. if(txProfile.ChargingProfileId == -1)
  1937. DEBUG_INFO("TxProfile found.\n");
  1938. else
  1939. DEBUG_INFO("TxProfile updated.\n");
  1940. // Required item
  1941. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1942. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1943. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1944. if(isUnitA)
  1945. {
  1946. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1947. 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++)
  1948. {
  1949. 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"));
  1950. 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?
  1951. 3:
  1952. 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")));
  1953. 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")));
  1954. }
  1955. }
  1956. else
  1957. {
  1958. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1959. 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++)
  1960. {
  1961. 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"));
  1962. 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?
  1963. 3:
  1964. 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")));
  1965. 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));
  1966. }
  1967. }
  1968. // Optional item
  1969. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1970. {
  1971. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1972. }
  1973. else
  1974. {
  1975. sprintf((char*)txProfile.ValidFrom, " ");
  1976. }
  1977. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1978. {
  1979. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1980. }
  1981. else
  1982. {
  1983. sprintf((char*)txProfile.ValidTo, " ");
  1984. }
  1985. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1986. {
  1987. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1988. }
  1989. else
  1990. {
  1991. sprintf((char*)txProfile.RecurrencyKind, " ");
  1992. }
  1993. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1994. {
  1995. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1996. }
  1997. else
  1998. {
  1999. txProfile.TransactionId = -1;
  2000. }
  2001. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2002. {
  2003. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2004. }
  2005. else
  2006. {
  2007. txProfile.ChargingSchedule.Duration = 86400;
  2008. }
  2009. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2010. {
  2011. 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")));
  2012. }
  2013. else
  2014. {
  2015. 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));
  2016. }
  2017. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2018. {
  2019. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2020. }
  2021. else
  2022. {
  2023. txProfile.ChargingSchedule.MinChargingRate = -1;
  2024. }
  2025. }
  2026. }
  2027. }
  2028. else
  2029. {
  2030. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2031. {
  2032. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2035. }
  2036. if(txProfile.ChargingProfileId == -1)
  2037. DEBUG_INFO("TxProfile found.\n");
  2038. else
  2039. DEBUG_INFO("TxProfile updated.\n");
  2040. // Required item
  2041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2044. if(isUnitA)
  2045. {
  2046. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2047. 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++)
  2048. {
  2049. 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"));
  2050. 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?
  2051. 3:
  2052. 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")));
  2053. 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")));
  2054. }
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2059. 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++)
  2060. {
  2061. 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"));
  2062. 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?
  2063. 3:
  2064. 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")));
  2065. 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));
  2066. }
  2067. }
  2068. // Optional item
  2069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2070. {
  2071. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2072. }
  2073. else
  2074. {
  2075. sprintf((char*)txProfile.ValidFrom, " ");
  2076. }
  2077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2078. {
  2079. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2080. }
  2081. else
  2082. {
  2083. sprintf((char*)txProfile.ValidTo, " ");
  2084. }
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2086. {
  2087. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)txProfile.RecurrencyKind, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2094. {
  2095. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2096. }
  2097. else
  2098. {
  2099. txProfile.TransactionId = -1;
  2100. }
  2101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2102. {
  2103. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2104. }
  2105. else
  2106. {
  2107. txProfile.ChargingSchedule.Duration = 86400;
  2108. }
  2109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2110. {
  2111. 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")));
  2112. }
  2113. else
  2114. {
  2115. 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));
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2118. {
  2119. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2120. }
  2121. else
  2122. {
  2123. txProfile.ChargingSchedule.MinChargingRate = -1;
  2124. }
  2125. }
  2126. }
  2127. }
  2128. json_object_put(obj);
  2129. }
  2130. fclose(fp);
  2131. /*
  2132. if(txProfile.ChargingProfileId != -1)
  2133. {
  2134. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2135. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2136. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2137. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2138. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2139. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2140. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2141. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2142. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2143. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2144. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2146. {
  2147. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2148. {
  2149. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2150. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2151. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2152. }
  2153. }
  2154. }
  2155. else
  2156. DEBUG_INFO("TxProfile not found.\n");*/
  2157. }
  2158. // Search default tx profile
  2159. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2160. if((access(profileFileName, F_OK))==-1)
  2161. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2162. if((access(profileFileName, F_OK))!=-1)
  2163. {
  2164. fp = fopen(profileFileName, "r");
  2165. while(getline(&line, &len, fp) != -1)
  2166. {
  2167. json_object *obj = NULL;
  2168. obj = json_tokener_parse(line);
  2169. if(is_error(obj))
  2170. {
  2171. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2172. }
  2173. else
  2174. {
  2175. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2176. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2177. )
  2178. {
  2179. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2180. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2181. )
  2182. {
  2183. struct tm tmFrom, tmTo;
  2184. struct timeb tbFrom, tbTo;
  2185. 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) &&
  2186. (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))
  2187. {
  2188. tmFrom.tm_year -= 1900;
  2189. tmFrom.tm_mon -= 1;
  2190. tbFrom.time = mktime(&tmFrom);
  2191. tmTo.tm_year -= 1900;
  2192. tmTo.tm_mon -= 1;
  2193. tbTo.time = mktime(&tmTo);
  2194. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2195. {
  2196. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2197. {
  2198. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2201. }
  2202. if(defaultTxProfile.ChargingProfileId == -1)
  2203. DEBUG_INFO("TxDefaultProfile found.\n");
  2204. else
  2205. DEBUG_INFO("TxDefaultProfile updated.\n");
  2206. // Required item
  2207. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2208. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2209. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2210. if(isUnitA)
  2211. {
  2212. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2213. 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++)
  2214. {
  2215. 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"));
  2216. 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?
  2217. 3:
  2218. 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")));
  2219. 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")));
  2220. }
  2221. }
  2222. else
  2223. {
  2224. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2225. 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++)
  2226. {
  2227. 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"));
  2228. 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?
  2229. 3:
  2230. 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")));
  2231. 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));
  2232. }
  2233. }
  2234. // Optional item
  2235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2236. {
  2237. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2238. }
  2239. else
  2240. {
  2241. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2242. }
  2243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2244. {
  2245. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2246. }
  2247. else
  2248. {
  2249. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2250. }
  2251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2252. {
  2253. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2254. }
  2255. else
  2256. {
  2257. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2258. }
  2259. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2260. {
  2261. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2262. }
  2263. else
  2264. {
  2265. defaultTxProfile.TransactionId = -1;
  2266. }
  2267. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2268. {
  2269. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2270. }
  2271. else
  2272. {
  2273. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2274. }
  2275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2276. {
  2277. 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")));
  2278. }
  2279. else
  2280. {
  2281. 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));
  2282. }
  2283. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2284. {
  2285. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2286. }
  2287. else
  2288. {
  2289. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2290. }
  2291. }
  2292. }
  2293. }
  2294. else
  2295. {
  2296. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2297. {
  2298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2301. }
  2302. if(defaultTxProfile.ChargingProfileId == -1)
  2303. DEBUG_INFO("TxDefaultProfile found.\n");
  2304. else
  2305. DEBUG_INFO("TxDefaultProfile updated.\n");
  2306. // Required item
  2307. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2308. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2309. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2310. if(isUnitA)
  2311. {
  2312. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2313. 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++)
  2314. {
  2315. 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"));
  2316. 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?
  2317. 3:
  2318. 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")));
  2319. 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")));
  2320. }
  2321. }
  2322. else
  2323. {
  2324. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2325. 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++)
  2326. {
  2327. 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"));
  2328. 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?
  2329. 3:
  2330. 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")));
  2331. 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));
  2332. }
  2333. }
  2334. // Optional item
  2335. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2336. {
  2337. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2338. }
  2339. else
  2340. {
  2341. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2342. }
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2352. {
  2353. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2354. }
  2355. else
  2356. {
  2357. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2358. }
  2359. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2360. {
  2361. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2362. }
  2363. else
  2364. {
  2365. defaultTxProfile.TransactionId = -1;
  2366. }
  2367. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2368. {
  2369. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2370. }
  2371. else
  2372. {
  2373. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2376. {
  2377. 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")));
  2378. }
  2379. else
  2380. {
  2381. 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));
  2382. }
  2383. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2384. {
  2385. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2386. }
  2387. else
  2388. {
  2389. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2390. }
  2391. }
  2392. }
  2393. }
  2394. json_object_put(obj);
  2395. }
  2396. fclose(fp);
  2397. /*
  2398. if(defaultTxProfile.ChargingProfileId != -1)
  2399. {
  2400. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2401. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2402. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2403. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2404. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2405. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2406. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2407. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2408. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2409. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2410. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2411. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2412. {
  2413. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2414. {
  2415. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2416. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2417. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2418. }
  2419. }
  2420. }
  2421. else
  2422. DEBUG_INFO("TxDefaultProfile not found.\n");
  2423. DEBUG_INFO("------------------------------------\n");*/
  2424. }
  2425. // Search max profile
  2426. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2427. if((access(profileFileName, F_OK))!=-1)
  2428. {
  2429. fp = fopen(profileFileName, "r");
  2430. while(getline(&line, &len, fp) != -1)
  2431. {
  2432. json_object *obj = NULL;
  2433. obj = json_tokener_parse(line);
  2434. if(is_error(obj))
  2435. {
  2436. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2437. }
  2438. else
  2439. {
  2440. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2441. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2442. )
  2443. {
  2444. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2445. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2446. )
  2447. {
  2448. struct tm tmFrom, tmTo;
  2449. struct timeb tbFrom, tbTo;
  2450. 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) &&
  2451. (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))
  2452. {
  2453. tmFrom.tm_year -= 1900;
  2454. tmFrom.tm_mon -= 1;
  2455. tbFrom.time = mktime(&tmFrom);
  2456. tmTo.tm_year -= 1900;
  2457. tmTo.tm_mon -= 1;
  2458. tbTo.time = mktime(&tmTo);
  2459. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2460. {
  2461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2462. {
  2463. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2466. }
  2467. if(maxProfile.ChargingProfileId == -1)
  2468. DEBUG_INFO("MaxProfile found.\n");
  2469. else
  2470. DEBUG_INFO("MaxProfile updated.\n");
  2471. // Required item
  2472. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2473. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2474. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2475. if(isUnitA)
  2476. {
  2477. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2478. 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++)
  2479. {
  2480. 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"));
  2481. 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?
  2482. 3:
  2483. 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")));
  2484. 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")));
  2485. }
  2486. }
  2487. else
  2488. {
  2489. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2490. 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++)
  2491. {
  2492. 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"));
  2493. 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?
  2494. 3:
  2495. 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")));
  2496. 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));
  2497. }
  2498. }
  2499. // Optional item
  2500. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2501. {
  2502. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2503. }
  2504. else
  2505. {
  2506. sprintf((char*)maxProfile.ValidFrom, " ");
  2507. }
  2508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2509. {
  2510. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2511. }
  2512. else
  2513. {
  2514. sprintf((char*)maxProfile.ValidTo, " ");
  2515. }
  2516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2517. {
  2518. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2519. }
  2520. else
  2521. {
  2522. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2523. }
  2524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2525. {
  2526. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2527. }
  2528. else
  2529. {
  2530. maxProfile.TransactionId = -1;
  2531. }
  2532. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2533. {
  2534. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2535. }
  2536. else
  2537. {
  2538. maxProfile.ChargingSchedule.Duration = 86400;
  2539. }
  2540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2541. {
  2542. 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")));
  2543. }
  2544. else
  2545. {
  2546. 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));
  2547. }
  2548. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2549. {
  2550. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2551. }
  2552. else
  2553. {
  2554. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. else
  2560. {
  2561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2562. {
  2563. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2566. }
  2567. if(maxProfile.ChargingProfileId == -1)
  2568. DEBUG_INFO("MaxProfile found.\n");
  2569. else
  2570. DEBUG_INFO("MaxProfile updated.\n");
  2571. // Required item
  2572. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2573. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2574. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2575. if(isUnitA)
  2576. {
  2577. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2578. 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++)
  2579. {
  2580. 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"));
  2581. 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?
  2582. 3:
  2583. 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")));
  2584. 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")));
  2585. }
  2586. }
  2587. else
  2588. {
  2589. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2590. 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++)
  2591. {
  2592. 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"));
  2593. 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?
  2594. 3:
  2595. 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")));
  2596. 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));
  2597. }
  2598. }
  2599. // Optional item
  2600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2601. {
  2602. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2603. }
  2604. else
  2605. {
  2606. sprintf((char*)maxProfile.ValidFrom, " ");
  2607. }
  2608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2609. {
  2610. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2611. }
  2612. else
  2613. {
  2614. sprintf((char*)maxProfile.ValidTo, " ");
  2615. }
  2616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2617. {
  2618. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2619. }
  2620. else
  2621. {
  2622. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2623. }
  2624. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2625. {
  2626. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2627. }
  2628. else
  2629. {
  2630. maxProfile.TransactionId = -1;
  2631. }
  2632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2633. {
  2634. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2635. }
  2636. else
  2637. {
  2638. maxProfile.ChargingSchedule.Duration = 86400;
  2639. }
  2640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2641. {
  2642. 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")));
  2643. }
  2644. else
  2645. {
  2646. 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));
  2647. }
  2648. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2649. {
  2650. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2651. }
  2652. else
  2653. {
  2654. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2655. }
  2656. }
  2657. }
  2658. }
  2659. json_object_put(obj);
  2660. }
  2661. fclose(fp);
  2662. /*
  2663. if(maxProfile.ChargingProfileId !=-1)
  2664. {
  2665. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2666. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2667. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2668. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2669. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2670. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2671. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2672. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2673. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2674. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2675. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2677. {
  2678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2679. {
  2680. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2681. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2682. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2683. }
  2684. }
  2685. }
  2686. else
  2687. DEBUG_INFO("MaxProfile not found.\n");
  2688. DEBUG_INFO("------------------------------------\n");*/
  2689. }
  2690. /*
  2691. * Align found profile start schedule & periods
  2692. */
  2693. //DEBUG_INFO("====================================\n");
  2694. /*
  2695. // For local test usage, force modify found profile start schedule info
  2696. 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);
  2697. 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);
  2698. 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);
  2699. */
  2700. if(txProfile.ChargingProfileId != -1)
  2701. {
  2702. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2703. {
  2704. if(txProfile.ChargingSchedule.Duration != -1)
  2705. {
  2706. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2707. 0:
  2708. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2709. }
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2713. {
  2714. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2717. if(idxPeriod > 0)
  2718. {
  2719. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2720. {
  2721. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2728. {
  2729. if(txProfile.ChargingSchedule.Duration != -1)
  2730. {
  2731. 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?
  2732. 0:
  2733. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2734. }
  2735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2736. {
  2737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2738. {
  2739. 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?
  2740. 0:
  2741. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2742. if(idxPeriod > 0)
  2743. {
  2744. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2745. {
  2746. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2747. }
  2748. }
  2749. }
  2750. }
  2751. }
  2752. else
  2753. {
  2754. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2755. {
  2756. if(txProfile.ChargingSchedule.Duration != -1)
  2757. {
  2758. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2759. 0:
  2760. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2761. }
  2762. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2763. {
  2764. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2765. {
  2766. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2769. if(idxPeriod > 0)
  2770. {
  2771. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2772. {
  2773. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. else
  2780. {
  2781. if(txProfile.ChargingSchedule.Duration != -1)
  2782. {
  2783. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2784. 0:
  2785. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2786. }
  2787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2788. {
  2789. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2790. {
  2791. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2792. 0:
  2793. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2794. if(idxPeriod > 0)
  2795. {
  2796. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2797. {
  2798. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2799. }
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. /*
  2806. DEBUG_INFO("txProfile after align.\n");
  2807. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2808. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2809. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2810. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2811. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2812. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2813. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2814. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2815. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2816. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2817. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2819. {
  2820. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2821. {
  2822. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2823. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2824. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2825. }
  2826. }*/
  2827. }
  2828. if(defaultTxProfile.ChargingProfileId != -1)
  2829. {
  2830. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2831. {
  2832. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2833. {
  2834. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2835. 0:
  2836. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2837. }
  2838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2839. {
  2840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2841. {
  2842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2843. 0:
  2844. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2845. if(idxPeriod > 0)
  2846. {
  2847. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2848. {
  2849. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2856. {
  2857. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2858. {
  2859. 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?
  2860. 0:
  2861. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2862. }
  2863. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2864. {
  2865. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2866. {
  2867. 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?
  2868. 0:
  2869. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2870. if(idxPeriod > 0)
  2871. {
  2872. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2873. {
  2874. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. else
  2881. {
  2882. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2883. {
  2884. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2885. {
  2886. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2887. 0:
  2888. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2889. }
  2890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2891. {
  2892. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2893. {
  2894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2895. 0:
  2896. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2897. if(idxPeriod > 0)
  2898. {
  2899. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2900. {
  2901. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2902. }
  2903. }
  2904. }
  2905. }
  2906. }
  2907. else
  2908. {
  2909. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2910. {
  2911. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2912. 0:
  2913. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2914. }
  2915. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2916. {
  2917. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2918. {
  2919. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2920. 0:
  2921. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2922. if(idxPeriod > 0)
  2923. {
  2924. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2925. {
  2926. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2927. }
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. /*
  2934. DEBUG_INFO("defaultTxProfile after align.\n");
  2935. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2936. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2937. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2938. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2939. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2940. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2941. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2942. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2943. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2944. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2945. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2946. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2949. {
  2950. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2951. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2952. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2953. }
  2954. }
  2955. DEBUG_INFO("------------------------------------\n");*/
  2956. }
  2957. if(maxProfile.ChargingProfileId != -1)
  2958. {
  2959. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2960. {
  2961. if(maxProfile.ChargingSchedule.Duration != -1)
  2962. {
  2963. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2964. 0:
  2965. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2966. }
  2967. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2968. {
  2969. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2970. {
  2971. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2972. 0:
  2973. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2974. if(idxPeriod > 0)
  2975. {
  2976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2977. {
  2978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2979. }
  2980. }
  2981. }
  2982. }
  2983. }
  2984. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2985. {
  2986. if(maxProfile.ChargingSchedule.Duration != -1)
  2987. {
  2988. 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?
  2989. 0:
  2990. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2991. }
  2992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2993. {
  2994. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2995. {
  2996. 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?
  2997. 0:
  2998. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2999. if(idxPeriod > 0)
  3000. {
  3001. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3002. {
  3003. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3004. }
  3005. }
  3006. }
  3007. }
  3008. }
  3009. else
  3010. {
  3011. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3012. {
  3013. if(maxProfile.ChargingSchedule.Duration != -1)
  3014. {
  3015. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3016. 0:
  3017. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3018. }
  3019. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3020. {
  3021. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3022. {
  3023. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3024. 0:
  3025. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3026. if(idxPeriod > 0)
  3027. {
  3028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3029. {
  3030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3031. }
  3032. }
  3033. }
  3034. }
  3035. }
  3036. else
  3037. {
  3038. if(maxProfile.ChargingSchedule.Duration != -1)
  3039. {
  3040. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3041. 0:
  3042. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3043. }
  3044. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3045. {
  3046. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3047. {
  3048. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3049. 0:
  3050. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3051. if(idxPeriod > 0)
  3052. {
  3053. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3054. {
  3055. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3056. }
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. /*
  3063. DEBUG_INFO("MaxProfile after align.\n");
  3064. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3065. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3066. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3067. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3068. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3069. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3070. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3071. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3072. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3073. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3074. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3076. {
  3077. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3078. {
  3079. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3080. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3081. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3082. }
  3083. }
  3084. DEBUG_INFO("------------------------------------\n");*/
  3085. }
  3086. /*
  3087. * Merge to conposite schedule
  3088. */
  3089. //DEBUG_INFO("====================================\n");
  3090. // Find each profile period quantity
  3091. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3092. {
  3093. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3094. limitMax = idx+1;
  3095. }
  3096. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3097. {
  3098. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3099. limitDef = idx+1;
  3100. }
  3101. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3102. {
  3103. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3104. limitTx = idx+1;
  3105. }
  3106. // TxProfile found, composite schedule based on it
  3107. if(txProfile.ChargingProfileId != -1)
  3108. {
  3109. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3110. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3111. {
  3112. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3113. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3114. (txProfile.ChargingSchedule.Duration > 0))
  3115. {
  3116. if(maxProfile.ChargingProfileId != -1)
  3117. {
  3118. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3119. {
  3120. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3121. {
  3122. if((maxProfile.ChargingSchedule.Duration > 0))
  3123. {
  3124. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3125. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3126. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3127. }
  3128. else
  3129. {
  3130. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3131. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3132. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3133. }
  3134. }
  3135. if(idxMaxPeriod == (limitMax-1))
  3136. {
  3137. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3138. {
  3139. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3140. {
  3141. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3142. compositePeriodIdx++;
  3143. }
  3144. else
  3145. {
  3146. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3147. }
  3148. }
  3149. }
  3150. }
  3151. }
  3152. else
  3153. {
  3154. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3155. {
  3156. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3157. compositePeriodIdx++;
  3158. }
  3159. else
  3160. {
  3161. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3162. }
  3163. }
  3164. }
  3165. if(idxTxPeriod == (limitTx-1))
  3166. {
  3167. if(defaultTxProfile.ChargingProfileId != -1)
  3168. {
  3169. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3170. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3171. {
  3172. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3173. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3174. (defaultTxProfile.ChargingSchedule.Duration>0))
  3175. {
  3176. if(maxProfile.ChargingProfileId != -1)
  3177. {
  3178. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3179. {
  3180. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3181. {
  3182. if((maxProfile.ChargingSchedule.Duration > 0))
  3183. {
  3184. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3185. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3186. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3187. }
  3188. else
  3189. {
  3190. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3191. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3192. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3193. }
  3194. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3195. {
  3196. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3197. {
  3198. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3199. compositePeriodIdx++;
  3200. }
  3201. else
  3202. {
  3203. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3204. }
  3205. }
  3206. // Delete duplicate period
  3207. if(compositePeriodIdx > 1)
  3208. {
  3209. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3210. {
  3211. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3213. compositePeriodIdx -= 1;
  3214. }
  3215. }
  3216. }
  3217. else
  3218. {
  3219. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3220. {
  3221. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3222. compositePeriodIdx++;
  3223. }
  3224. else
  3225. {
  3226. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3227. }
  3228. break;
  3229. }
  3230. }
  3231. }
  3232. else
  3233. {
  3234. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3235. {
  3236. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. compositePeriodIdx++;
  3238. }
  3239. else
  3240. {
  3241. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3242. }
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3251. else if(defaultTxProfile.ChargingProfileId != -1)
  3252. {
  3253. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3254. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3255. {
  3256. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3257. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3258. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3259. {
  3260. if(maxProfile.ChargingProfileId != -1)
  3261. {
  3262. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3263. {
  3264. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3265. {
  3266. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3267. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3268. if((maxProfile.ChargingSchedule.Duration > 0))
  3269. {
  3270. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3271. }
  3272. else
  3273. {
  3274. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3275. }
  3276. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3277. {
  3278. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3279. {
  3280. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3281. compositePeriodIdx++;
  3282. }
  3283. else
  3284. {
  3285. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3286. }
  3287. }
  3288. // Delete duplicate period
  3289. if(compositePeriodIdx > 1)
  3290. {
  3291. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3292. {
  3293. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3295. compositePeriodIdx -= 1;
  3296. }
  3297. }
  3298. }
  3299. else
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3302. {
  3303. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3304. compositePeriodIdx++;
  3305. }
  3306. else
  3307. {
  3308. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3309. }
  3310. break;
  3311. }
  3312. }
  3313. }
  3314. else
  3315. {
  3316. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3317. {
  3318. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3319. compositePeriodIdx++;
  3320. }
  3321. else
  3322. {
  3323. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3324. }
  3325. }
  3326. }
  3327. }
  3328. }
  3329. // Fill other period by MaxProfile
  3330. if(maxProfile.ChargingProfileId != -1)
  3331. {
  3332. if(compositePeriodIdx==0)
  3333. {
  3334. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3335. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3336. {
  3337. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3338. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3339. (maxProfile.ChargingSchedule.Duration > 0))
  3340. {
  3341. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3342. {
  3343. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3344. compositePeriodIdx++;
  3345. }
  3346. else
  3347. {
  3348. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3349. }
  3350. }
  3351. }
  3352. }
  3353. else
  3354. {
  3355. int lastCompositePeriodIdx = compositePeriodIdx;
  3356. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3357. {
  3358. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3359. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3360. (maxProfile.ChargingSchedule.Duration > 0))
  3361. {
  3362. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3363. {
  3364. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3365. {
  3366. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3367. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3368. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3369. }
  3370. else
  3371. {
  3372. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3373. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3374. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3375. }
  3376. }
  3377. if(tmpPeriod.Limit != -1)
  3378. {
  3379. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3380. {
  3381. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3382. {
  3383. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3384. compositePeriodIdx++;
  3385. }
  3386. else
  3387. {
  3388. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3389. }
  3390. }
  3391. // Delete duplicate period
  3392. if(compositePeriodIdx > 1)
  3393. {
  3394. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3395. {
  3396. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3398. compositePeriodIdx -= 1;
  3399. }
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. compositeProfile.ChargingSchedule.Duration = durationReq;
  3407. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3408. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3409. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3410. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3411. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3412. {
  3413. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3414. {
  3415. compositeProfile.ChargingProfileId = 1;
  3416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3419. }
  3420. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3421. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3422. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3423. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3424. }
  3425. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3426. if(line)
  3427. free(line);
  3428. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3429. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3430. }
  3431. //==========================================
  3432. // Init all share memory
  3433. //==========================================
  3434. int InitShareMemory()
  3435. {
  3436. int result = PASS;
  3437. int MeterSMId;
  3438. //creat ShmSysConfigAndInfo
  3439. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3440. {
  3441. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3442. result = FAIL;
  3443. }
  3444. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3445. {
  3446. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3447. result = FAIL;
  3448. }
  3449. else
  3450. {}
  3451. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3452. {
  3453. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3454. result = FAIL;
  3455. }
  3456. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3457. {
  3458. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3459. result = FAIL;
  3460. }
  3461. else
  3462. {}
  3463. //creat ShmPsuData
  3464. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3465. {
  3466. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3467. result = FAIL;
  3468. }
  3469. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3470. {
  3471. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3472. result = FAIL;
  3473. }
  3474. else
  3475. {}
  3476. //link ShmOCPP16Data
  3477. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3478. {
  3479. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3480. result = FAIL;
  3481. }
  3482. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3483. {
  3484. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3485. result = FAIL;
  3486. }
  3487. else
  3488. {}
  3489. //creat ShmOCPP16DataPH
  3490. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3491. {
  3492. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3493. result = FAIL;
  3494. }
  3495. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3496. {
  3497. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3498. result = FAIL;
  3499. }
  3500. else
  3501. {}
  3502. /****************************** For Initial Settings************************************************/
  3503. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3504. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3505. // allocate Configuration memory address
  3506. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3507. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3509. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3510. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3511. //offline MeterValue Interval
  3512. TempMeterValueInterval = 0;
  3513. return result;
  3514. }
  3515. int ProcessShareMemory()
  3516. {
  3517. int result = PASS;
  3518. if(InitShareMemory() == FAIL)
  3519. {
  3520. DEBUG_ERROR("InitShareMemory NG\n");
  3521. if(ShmStatusCodeData!=NULL)
  3522. {
  3523. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3524. }
  3525. result = FAIL;
  3526. }
  3527. // Model name parsing
  3528. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3529. {
  3530. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3532. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3533. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3535. ) // 'D' means DC
  3536. {
  3537. // DO series
  3538. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3539. {
  3540. gunTotalNumber += 1;
  3541. gunType[gun_index] = GUN_TYPE_DO;
  3542. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3543. {
  3544. case Gun_Type_Chademo:
  3545. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3546. break;
  3547. case Gun_Type_CCS_2:
  3548. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3549. break;
  3550. case Gun_Type_GB:
  3551. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3552. break;
  3553. case Gun_Type_AC:
  3554. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3555. break;
  3556. default:
  3557. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3558. break;
  3559. }
  3560. }
  3561. }
  3562. else
  3563. {
  3564. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3565. {
  3566. gunTotalNumber += 1;
  3567. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3568. {
  3569. case Gun_Type_Chademo:
  3570. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3571. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3572. break;
  3573. case Gun_Type_CCS_2:
  3574. gunType[gun_index] = GUN_TYPE_CCS;
  3575. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3576. break;
  3577. case Gun_Type_GB:
  3578. gunType[gun_index] = GUN_TYPE_GBT;
  3579. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3580. break;
  3581. case Gun_Type_AC:
  3582. gunType[gun_index] = GUN_TYPE_AC;
  3583. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3584. break;
  3585. default:
  3586. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3587. break;
  3588. }
  3589. }
  3590. }
  3591. }
  3592. else
  3593. {
  3594. DEBUG_ERROR("Model name parsing fail.\n");
  3595. result = FAIL;
  3596. }
  3597. if(result != PASS)sleep(5);
  3598. return result;
  3599. }
  3600. void checkRemoteStart(uint8_t connectorIdInt)
  3601. {
  3602. uint8_t tempIndex;
  3603. int result = PASS;
  3604. char cmdBuf[512];
  3605. //check Transaction active
  3606. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3607. {
  3608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3609. {
  3610. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3611. }
  3612. else
  3613. {
  3614. tempIndex = connectorIdInt -1;
  3615. }
  3616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3617. {
  3618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3619. {
  3620. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3621. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3622. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3623. {
  3624. //Reserved
  3625. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3626. }
  3627. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3628. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3629. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3630. {
  3631. //Reserved
  3632. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3633. result = FAIL;
  3634. goto end;
  3635. }
  3636. else
  3637. {
  3638. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3639. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3640. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3641. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3642. {
  3643. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3644. result = FAIL;
  3645. goto end;
  3646. }
  3647. }//END FOR ELSE
  3648. }
  3649. }// END FOR CHAdeMO_QUANTITY
  3650. }
  3651. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3652. {
  3653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3654. {
  3655. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3656. }
  3657. else
  3658. {
  3659. tempIndex = connectorIdInt -1;
  3660. }
  3661. for (int index = 0; index < CCS_QUANTITY; index++)
  3662. {
  3663. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3664. {
  3665. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3667. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3668. {
  3669. //Reserved
  3670. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3671. }
  3672. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3673. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3674. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3675. {
  3676. //Reserved
  3677. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3678. result = FAIL;
  3679. goto end;
  3680. }
  3681. else
  3682. {
  3683. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3684. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3685. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3686. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3687. {
  3688. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3689. result = FAIL;
  3690. goto end;
  3691. }
  3692. }// END FOR ELSE
  3693. }
  3694. }// END FOR CCS_QUANTITY
  3695. }
  3696. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3697. {
  3698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3699. {
  3700. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3701. }
  3702. else
  3703. {
  3704. tempIndex = connectorIdInt -1;
  3705. }
  3706. for (int index = 0; index < GB_QUANTITY; index++)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3709. {
  3710. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3711. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3712. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3713. {
  3714. //Reserved
  3715. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3716. }
  3717. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3718. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3719. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3720. {
  3721. //Reserved
  3722. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3723. result = FAIL;
  3724. goto end;
  3725. }
  3726. else
  3727. {
  3728. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3729. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3730. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3731. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3732. {
  3733. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3734. result = FAIL;
  3735. goto end;
  3736. }
  3737. }// END FOR ELSE
  3738. }
  3739. } // END FOR GB_QUANTITY
  3740. }
  3741. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3742. {
  3743. tempIndex = connectorIdInt -1;
  3744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3747. {
  3748. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3750. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3751. {
  3752. //Reserved
  3753. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3754. }
  3755. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3757. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3758. {
  3759. //Reserved
  3760. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3761. result = FAIL;
  3762. goto end;
  3763. }
  3764. else
  3765. {
  3766. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3767. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3768. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3769. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3770. {
  3771. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3772. result = FAIL;
  3773. goto end;
  3774. }
  3775. }// END FOR ELSE
  3776. }
  3777. } // END FOR GB_QUANTITY
  3778. }
  3779. else
  3780. {
  3781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3782. {
  3783. tempIndex = 2;
  3784. }
  3785. else
  3786. {
  3787. tempIndex = connectorIdInt -1;
  3788. }
  3789. for (int index = 0; index < AC_QUANTITY; index++)
  3790. {
  3791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3792. {
  3793. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3795. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3796. {
  3797. //Reserved
  3798. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3799. }
  3800. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3801. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3802. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3803. {
  3804. //Reserved
  3805. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3806. result = FAIL;
  3807. goto end;
  3808. }
  3809. else
  3810. {
  3811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3812. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3813. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3815. {
  3816. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3817. result = FAIL;
  3818. goto end;
  3819. }
  3820. }//END FOR ELSE
  3821. }
  3822. }// END FOR AC_QUANTITY
  3823. }
  3824. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3825. {
  3826. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3827. {
  3828. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3829. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3830. {
  3831. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3832. system(cmdBuf);
  3833. }
  3834. }
  3835. else
  3836. {
  3837. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3838. result = FAIL;
  3839. }
  3840. }
  3841. end:
  3842. if(result == PASS)
  3843. {
  3844. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3845. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3846. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3847. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3849. }
  3850. }
  3851. void CheckSystemValue(void)
  3852. {
  3853. char filenmae[100]={0};
  3854. char str[100]={0};
  3855. int tempIndex = 0;
  3856. //===============================
  3857. // send Heartbeat
  3858. //===============================
  3859. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3860. {
  3861. //parameter for test
  3862. sendHeartbeatRequest(0);
  3863. //==============================================
  3864. // Reset Waiting Time
  3865. //==============================================
  3866. HeartBeatWithNOResponse += 2;
  3867. }
  3868. //===============================
  3869. // Credit deduct report
  3870. //===============================
  3871. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3872. {
  3873. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3874. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3875. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3876. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3877. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3878. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3879. }
  3880. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3881. {
  3882. OCPP_query_deduct_info();
  3883. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3884. }
  3885. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3886. {
  3887. // ClockAlign MeterValue
  3888. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3889. {
  3890. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3891. {
  3892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3893. {
  3894. tempIndex = ((gun_index==2) ? 1: 0);
  3895. }
  3896. else
  3897. {
  3898. tempIndex = gun_index;
  3899. }
  3900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3901. {
  3902. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3903. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3904. {
  3905. reqClockAlignMeter[gun_index] = 1;
  3906. }
  3907. }// End for CHAdeMO
  3908. }
  3909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3910. {
  3911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3912. {
  3913. tempIndex = ((gun_index==2) ? 1: 0);
  3914. }
  3915. else
  3916. {
  3917. tempIndex = gun_index;
  3918. }
  3919. for (int index = 0; index < CCS_QUANTITY; index++)
  3920. {
  3921. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3922. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3923. {
  3924. reqClockAlignMeter[gun_index] = 1;
  3925. }
  3926. } // End for CCS
  3927. }
  3928. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3929. {
  3930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3931. {
  3932. tempIndex = ((gun_index==2) ? 1: 0);
  3933. }
  3934. else
  3935. {
  3936. tempIndex = gun_index;
  3937. }
  3938. for (int index = 0; index < GB_QUANTITY; index++)
  3939. {
  3940. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3941. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3942. {
  3943. reqClockAlignMeter[gun_index] = 1;
  3944. }
  3945. }// End for GB
  3946. }
  3947. else if(gunType[gun_index] == GUN_TYPE_DO)
  3948. {
  3949. tempIndex = gun_index;
  3950. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3951. {
  3952. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3953. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3954. {
  3955. reqClockAlignMeter[gun_index] = 1;
  3956. }
  3957. }
  3958. }
  3959. else
  3960. {
  3961. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3962. {
  3963. tempIndex = 2;
  3964. }
  3965. else
  3966. {
  3967. tempIndex = gun_index;
  3968. }
  3969. for (int index = 0; index < AC_QUANTITY; index++)
  3970. {
  3971. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3972. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3973. {
  3974. reqClockAlignMeter[gun_index] = 1;
  3975. }
  3976. }//End for AC
  3977. }
  3978. }
  3979. }
  3980. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3981. {
  3982. //==========================================
  3983. // Check remote start without connector id
  3984. //==========================================
  3985. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3986. {
  3987. int connectorIdInt = -1;
  3988. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3989. {
  3990. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3991. {
  3992. connectorIdInt = (gun_index+1);
  3993. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3994. checkRemoteStart(connectorIdInt);
  3995. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3996. break;
  3997. }
  3998. }
  3999. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4000. {
  4001. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4002. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4003. }
  4004. }
  4005. //==========================================
  4006. // csu trigger DataTransferReq
  4007. //==========================================
  4008. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4009. {
  4010. sendDataTransferRequest(gun_index);
  4011. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4012. }
  4013. //===============================
  4014. // CSU Trigger Authorize Request
  4015. //===============================
  4016. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4017. {
  4018. sendAuthorizeRequest(0);
  4019. authorizeRetryTimes = authorizeRetryTimes + 1;
  4020. if(authorizeRetryTimes < 3)
  4021. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4022. }
  4023. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4024. {
  4025. authorizeRetryTimes = 0;
  4026. SetOcppConnStatus(FALSE);
  4027. server_sign = FALSE;
  4028. }
  4029. 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))
  4030. {
  4031. sendAuthorizeRequest(0);
  4032. }
  4033. //==============================================
  4034. // Charger start transaction
  4035. //==============================================
  4036. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4037. {
  4038. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4039. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4040. sendStartTransactionRequest(gun_index);
  4041. refreshStartTimer(&clientTime.StartTransaction);
  4042. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4043. //storeTempStopTransaction(gun_index);
  4044. }
  4045. //==============================================
  4046. // Charger stop transaction
  4047. //==============================================
  4048. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4049. {
  4050. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4051. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4052. sendStopTransactionRequest(gun_index);
  4053. refreshStartTimer(&clientTime.StopTransaction);
  4054. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4055. }
  4056. //==============================================
  4057. // Charger status report
  4058. //==============================================
  4059. //--- Check Mode Change ---//
  4060. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4061. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4062. {
  4063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4064. {
  4065. tempIndex = ((gun_index==2) ? 1: 0);
  4066. }
  4067. else
  4068. {
  4069. tempIndex = gun_index;
  4070. }
  4071. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4072. {
  4073. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4074. {
  4075. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4076. {
  4077. // Sent unplug message for California pricing logic
  4078. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4079. {
  4080. uint8_t ts[20];
  4081. getNowDatetime(ts);
  4082. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4083. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4084. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4085. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4086. }
  4087. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4088. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4089. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4090. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4091. {
  4092. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4093. if((access(filenmae,F_OK))!=-1)
  4094. {
  4095. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4096. sprintf(str,"rm -f %s",filenmae);
  4097. system(str);
  4098. }
  4099. }
  4100. }
  4101. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4102. #if 1 // for TempStopTransaction
  4103. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4104. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4105. {
  4106. checkTempStopTransaction(gun_index);
  4107. }
  4108. #endif
  4109. }
  4110. }
  4111. }
  4112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((gun_index==2) ? 1: 0);
  4117. }
  4118. else
  4119. {
  4120. tempIndex = gun_index;
  4121. }
  4122. for (int index = 0; index < CCS_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4125. {
  4126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4127. {
  4128. // Sent unplug message for California pricing logic
  4129. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4130. {
  4131. uint8_t ts[20];
  4132. getNowDatetime(ts);
  4133. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4134. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4135. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4136. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4137. }
  4138. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4139. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4140. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4141. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4142. {
  4143. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4144. if((access(filenmae,F_OK))!=-1)
  4145. {
  4146. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4147. sprintf(str,"rm -f %s",filenmae);
  4148. system(str);
  4149. }
  4150. }
  4151. }
  4152. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4153. #if 1 // for TempStopTransaction
  4154. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4155. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4156. {
  4157. checkTempStopTransaction(gun_index);
  4158. }
  4159. #endif
  4160. }
  4161. }
  4162. }
  4163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4164. {
  4165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4166. {
  4167. tempIndex = ((gun_index==2) ? 1: 0);
  4168. }
  4169. else
  4170. {
  4171. tempIndex = gun_index;
  4172. }
  4173. for (int index = 0; index < GB_QUANTITY; index++)
  4174. {
  4175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4176. {
  4177. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4178. {
  4179. // Sent unplug message for California pricing logic
  4180. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4181. {
  4182. uint8_t ts[20];
  4183. getNowDatetime(ts);
  4184. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4185. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4187. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4188. }
  4189. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4190. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4191. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4192. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4193. {
  4194. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4195. if((access(filenmae,F_OK))!=-1)
  4196. {
  4197. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4198. sprintf(str,"rm -f %s",filenmae);
  4199. system(str);
  4200. }
  4201. }
  4202. }
  4203. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4204. #if 1 // for TempStopTransaction
  4205. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4206. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4207. {
  4208. checkTempStopTransaction(gun_index);
  4209. }
  4210. #endif
  4211. }
  4212. }
  4213. }
  4214. else if(gunType[gun_index] == GUN_TYPE_DO)
  4215. {
  4216. tempIndex = gun_index;
  4217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4218. {
  4219. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4220. {
  4221. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4222. {
  4223. // Sent unplug message for California pricing logic
  4224. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4225. {
  4226. uint8_t ts[20];
  4227. getNowDatetime(ts);
  4228. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4229. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4230. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4231. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4232. }
  4233. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4234. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4235. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4236. 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
  4237. {
  4238. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4239. if((access(filenmae,F_OK))!=-1)
  4240. {
  4241. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4242. sprintf(str,"rm -f %s",filenmae);
  4243. system(str);
  4244. }
  4245. }
  4246. }
  4247. 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);
  4248. #if 1 // for TempStopTransaction
  4249. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4250. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4251. {
  4252. checkTempStopTransaction(gun_index);
  4253. }
  4254. #endif
  4255. }
  4256. }
  4257. }
  4258. else
  4259. {
  4260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4261. {
  4262. tempIndex = 2;
  4263. }
  4264. else
  4265. {
  4266. tempIndex = gun_index;
  4267. }
  4268. for (int index = 0; index < AC_QUANTITY; index++)
  4269. {
  4270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4271. {
  4272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4273. {
  4274. // Sent unplug message for California pricing logic
  4275. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4276. {
  4277. uint8_t ts[20];
  4278. getNowDatetime(ts);
  4279. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4280. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4281. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4282. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4283. }
  4284. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4285. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4286. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4287. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4288. {
  4289. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4290. if((access(filenmae,F_OK))!=-1)
  4291. {
  4292. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4293. sprintf(str,"rm -f %s",filenmae);
  4294. system(str);
  4295. }
  4296. }
  4297. }
  4298. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4299. #if 1 // for TempStopTransaction
  4300. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4301. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4302. {
  4303. checkTempStopTransaction(gun_index);
  4304. }
  4305. #endif
  4306. }
  4307. }// END
  4308. }
  4309. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4310. (
  4311. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4312. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4313. )
  4314. )
  4315. {
  4316. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4317. sendStatusNotificationRequest(gun_index);
  4318. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4319. }
  4320. //==============================================
  4321. // TCCI reader status report
  4322. //==============================================
  4323. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4324. {
  4325. reportReaderStatus(gun_index);
  4326. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4327. }
  4328. //==============================================
  4329. // CSU Trigger Smart Charging Profile
  4330. //==============================================
  4331. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4332. {
  4333. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4334. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4335. }
  4336. //==============================================
  4337. // Meter report
  4338. //==============================================
  4339. // Trigger MeterValue
  4340. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4341. {
  4342. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4343. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4344. }
  4345. // Clock-aligned Meter value
  4346. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4347. {
  4348. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4349. reqClockAlignMeter[gun_index] = 0;
  4350. }
  4351. // Sample period MeterValue
  4352. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4353. {
  4354. //check Transaction active
  4355. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4356. {
  4357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4358. {
  4359. tempIndex = ((gun_index==2) ? 1: 0);
  4360. }
  4361. else
  4362. {
  4363. tempIndex = gun_index;
  4364. }
  4365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4366. {
  4367. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4368. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4369. {
  4370. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4371. {
  4372. reqSampleMeter[gun_index] = 1;
  4373. }
  4374. }
  4375. }// End for CHAdeMO
  4376. }
  4377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4378. {
  4379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4380. {
  4381. tempIndex = ((gun_index==2) ? 1: 0);
  4382. }
  4383. else
  4384. {
  4385. tempIndex = gun_index;
  4386. }
  4387. for (int index = 0; index < CCS_QUANTITY; index++)
  4388. {
  4389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4390. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4391. {
  4392. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4393. {
  4394. reqSampleMeter[gun_index] = 1;
  4395. }
  4396. }
  4397. } // End for CCS
  4398. }
  4399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4400. {
  4401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4402. {
  4403. tempIndex = ((gun_index==2) ? 1: 0);
  4404. }
  4405. else
  4406. {
  4407. tempIndex = gun_index;
  4408. }
  4409. for (int index = 0; index < GB_QUANTITY; index++)
  4410. {
  4411. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4412. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4413. {
  4414. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4415. {
  4416. reqSampleMeter[gun_index] = 1;
  4417. }
  4418. }
  4419. }// End for GB
  4420. }
  4421. else if(gunType[gun_index] == GUN_TYPE_DO)
  4422. {
  4423. tempIndex = gun_index;
  4424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4425. {
  4426. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4427. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4428. {
  4429. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4430. {
  4431. reqSampleMeter[gun_index] = 1;
  4432. }
  4433. }
  4434. }
  4435. }
  4436. else
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4439. {
  4440. tempIndex = 2;
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < AC_QUANTITY; index++)
  4447. {
  4448. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4450. {
  4451. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4452. {
  4453. reqSampleMeter[gun_index] = 1;
  4454. }
  4455. }
  4456. }//End for AC
  4457. }
  4458. if(reqSampleMeter[gun_index] == 1)
  4459. {
  4460. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4461. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4462. //storeTempStopTransaction(gun_index);
  4463. reqSampleMeter[gun_index] = 0;
  4464. }
  4465. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4466. }
  4467. //==============================================
  4468. // Check Connector reserved
  4469. //==============================================
  4470. //===============================
  4471. // Check if Reserve is expired
  4472. //===============================
  4473. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4474. {
  4475. double diff_t;
  4476. struct tm tp;
  4477. // current time
  4478. time_t t = time(NULL);
  4479. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4480. tp.tm_isdst = -1;
  4481. time_t utc = mktime(&tp);
  4482. diff_t = difftime(utc, t);
  4483. if(diff_t <= 0)
  4484. {
  4485. DEBUG_INFO("reserve expired.\n");
  4486. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4487. }
  4488. }//END OF Check if Reserve is expired
  4489. //==========================================
  4490. // csu trigger FirmwareStatusNotificationReq
  4491. //==========================================
  4492. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4493. {
  4494. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4495. }
  4496. //==========================================
  4497. // csu trigger DiagnosticsStatusNotificationReq
  4498. //==========================================
  4499. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4500. {
  4501. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4502. }
  4503. //==========================================
  4504. // csu trigger CancelReservationConf
  4505. //==========================================
  4506. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4507. {
  4508. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4509. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4510. }
  4511. //==========================================
  4512. // csu trigger ChangeAvailabilityConf
  4513. //==========================================
  4514. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4515. {
  4516. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4517. }
  4518. //==========================================
  4519. // csu trigger UnlockConnectorConf
  4520. //==========================================
  4521. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4522. {
  4523. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4524. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4525. }
  4526. //==========================================
  4527. // csu trigger ReserveNowConf
  4528. //==========================================
  4529. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4530. {
  4531. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4532. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4533. }
  4534. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4535. {
  4536. sendSignCertificateRequest();
  4537. }
  4538. }
  4539. }
  4540. //==========================================
  4541. // send request routine
  4542. //==========================================
  4543. int sendAuthorizeRequest(int gun_index)
  4544. {
  4545. mtrace();
  4546. int result = FAIL;
  4547. char message[100]={0};
  4548. char guid[37];
  4549. char tempdata[65]={0};
  4550. DEBUG_INFO("sendAuthorizeRequest...\n");
  4551. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4552. //Local Authorize
  4553. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4554. {
  4555. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4556. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4557. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4558. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4559. result = PASS;
  4560. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4561. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4562. authorizeRetryTimes = 0;
  4563. return result;
  4564. }
  4565. 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))||
  4566. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4567. {
  4568. // Query from cache
  4569. DEBUG_INFO("Authorize from cache.\n");
  4570. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4571. // Query from list
  4572. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4573. {
  4574. DEBUG_INFO("Authorize from list.\n");
  4575. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4576. }
  4577. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4578. {
  4579. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4580. {
  4581. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4582. }
  4583. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4584. {
  4585. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4586. }
  4587. if(!GetOcppConnStatus())
  4588. {
  4589. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4590. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4591. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4592. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4593. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4594. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4595. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4596. authorizeRetryTimes = 0;
  4597. return result;
  4598. }
  4599. }
  4600. else
  4601. {
  4602. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4603. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4604. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4605. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4606. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4607. else
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4609. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4610. result = PASS;
  4611. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4612. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4613. authorizeRetryTimes = 0;
  4614. return result;
  4615. }
  4616. }
  4617. //initialize struct Authorize
  4618. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4619. //get data from shared memory
  4620. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4621. random_uuid(guid);
  4622. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4623. LWS_Send(message);
  4624. sprintf(tempdata, "Authorize,%d", gun_index);
  4625. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4626. {
  4627. result = PASS;
  4628. DEBUG_INFO("Authorize mapItem pass\n");
  4629. }
  4630. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4631. return result;
  4632. }
  4633. int sendBootNotificationRequest(void)
  4634. {
  4635. mtrace();
  4636. int result = FAIL;
  4637. char message[500]={0}, payload[700]={0};
  4638. char guid[37]={0};
  4639. char tempdata[65]={0};
  4640. // Fill BootNotification fields
  4641. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4642. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4643. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4644. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4645. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4648. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4649. ShmOCPP16DataPH->ChargeBoxId
  4650. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4651. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4652. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4653. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4654. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4655. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4656. random_uuid(guid);
  4657. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4658. LWS_Send(message);
  4659. sprintf(tempdata, "BootNotification,0");
  4660. 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*/)
  4661. {
  4662. result = PASS;
  4663. }
  4664. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4665. strcpy(queuedata,message);
  4666. return result;
  4667. }
  4668. int sendDataTransferRequest(int gun_index)
  4669. {
  4670. mtrace();
  4671. char message[1000]={0};
  4672. char guid[37]={0};
  4673. char tempdata[65]={0};
  4674. int result = FAIL;
  4675. random_uuid(guid);
  4676. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4677. MESSAGE_TYPE_CALL,
  4678. guid,
  4679. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4680. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4681. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4682. LWS_Send(message);
  4683. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4684. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4685. {
  4686. result = PASS;
  4687. DEBUG_INFO("DataTransfer mapItem pass\n");
  4688. }
  4689. return result;
  4690. }
  4691. int sendDiagnosticsStatusNotificationRequest(char *status)
  4692. {
  4693. mtrace();
  4694. int result = FAIL;
  4695. char message[110]={0};
  4696. char guid[37]={0};
  4697. char tempdata[65]={0};
  4698. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4699. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4700. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4701. random_uuid(guid);
  4702. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4703. LWS_SendNow(message);
  4704. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4705. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4706. {
  4707. result = PASS;
  4708. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4709. }
  4710. //#ifdef SystemLogMessage
  4711. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4712. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4713. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4714. //#endif
  4715. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4716. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4717. //record status
  4718. if(strcmp(status,"Idle")==0)
  4719. {
  4720. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4721. }
  4722. else if(strcmp(status,"Uploaded")==0)
  4723. {
  4724. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4725. }
  4726. else if(strcmp(status,"UploadFailed")==0)
  4727. {
  4728. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4729. }
  4730. else if(strcmp(status,"Uploading")==0)
  4731. {
  4732. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4733. }
  4734. return result;
  4735. }
  4736. int sendFirmwareStatusNotificationRequest(char *status)
  4737. {
  4738. mtrace();
  4739. int result = FAIL;
  4740. char message[110]={0};
  4741. char guid[37]={0};
  4742. char tempdata[65]={0};
  4743. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4744. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4745. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4746. random_uuid(guid);
  4747. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4748. LWS_SendNow(message);
  4749. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4750. 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*/)
  4751. {
  4752. result = PASS;
  4753. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4754. }
  4755. //#ifdef SystemLogMessage
  4756. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4757. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4758. //#endif
  4759. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4760. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4761. //record status
  4762. if(strcmp(status,"Downloaded")==0)
  4763. {
  4764. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4765. }
  4766. else if(strcmp(status,"DownloadFailed")==0)
  4767. {
  4768. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4769. }
  4770. else if(strcmp(status,"Downloading")==0)
  4771. {
  4772. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4773. }
  4774. else if(strcmp(status,"Idle")==0)
  4775. {
  4776. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4777. }
  4778. else if(strcmp(status,"InstallationFailed")==0)
  4779. {
  4780. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4781. }
  4782. else if(strcmp(status,"Installing")==0)
  4783. {
  4784. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4785. }
  4786. else if(strcmp(status,"Installed")==0)
  4787. {
  4788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4789. }
  4790. return result;
  4791. }
  4792. int sendHeartbeatRequest(int gun_index)
  4793. {
  4794. mtrace();
  4795. int result = FAIL;
  4796. char message[80]={0};
  4797. char guid[37]={0};
  4798. char tempdata[65]={0};
  4799. random_uuid(guid);
  4800. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4801. , MESSAGE_TYPE_CALL
  4802. , guid );
  4803. LWS_Send(message);
  4804. sprintf(tempdata, "Heartbeat,%d", 0);
  4805. 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*/)
  4806. {
  4807. result = PASS;
  4808. }
  4809. return result;
  4810. }
  4811. int sendStartTransactionRequest(int gun_index)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. char message[250]={0};
  4816. char guid[37]={0};
  4817. struct timeval tmnow;
  4818. struct tm *tm;
  4819. char buf[28];//, usec_buf[6];
  4820. char tempdata[65]={0};
  4821. int tempIndex = 0;
  4822. DEBUG_INFO("sendStartTransactionRequest...\n");
  4823. gettimeofday(&tmnow, NULL);
  4824. time_t t;
  4825. t = time(NULL);
  4826. /*UTC time and date*/
  4827. tm = gmtime(&t);
  4828. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4829. #if 0 // remove temporally
  4830. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4831. strcat(buf,".");
  4832. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4833. strcat(buf,usec_buf);
  4834. #endif
  4835. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4836. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4837. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4838. // clear StartTransaction Response
  4839. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4840. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4841. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4842. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4843. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4845. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4846. {
  4847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4848. {
  4849. tempIndex = ((gun_index==2) ? 1: 0);
  4850. }
  4851. else
  4852. {
  4853. tempIndex = gun_index;
  4854. }
  4855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4856. {
  4857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4858. {
  4859. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4860. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4861. }
  4862. }
  4863. }
  4864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4865. {
  4866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4867. {
  4868. tempIndex = ((gun_index==2) ? 1: 0);
  4869. }
  4870. else
  4871. {
  4872. tempIndex = gun_index;
  4873. }
  4874. for (int index = 0; index < CCS_QUANTITY; index++)
  4875. {
  4876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4877. {
  4878. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4879. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4880. }
  4881. }
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < GB_QUANTITY; index++)
  4894. {
  4895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4896. {
  4897. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4898. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4899. }
  4900. }
  4901. }
  4902. else if(gunType[gun_index] == GUN_TYPE_DO)
  4903. {
  4904. tempIndex = gun_index;
  4905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4906. {
  4907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4908. {
  4909. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4910. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4911. }
  4912. }
  4913. }
  4914. else
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4917. {
  4918. tempIndex = 2;
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < AC_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4927. {
  4928. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4929. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4930. }
  4931. }
  4932. }
  4933. random_uuid(guid);
  4934. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4935. {
  4936. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4937. , gun_index +1
  4938. , MESSAGE_TYPE_CALL
  4939. , guid
  4940. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4941. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4942. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4943. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4944. }
  4945. else
  4946. {
  4947. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4948. , gun_index +1
  4949. , MESSAGE_TYPE_CALL
  4950. , guid
  4951. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4952. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4953. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4954. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4955. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4956. }
  4957. #if 1
  4958. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4959. 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*/)
  4960. {
  4961. result = PASS;
  4962. }
  4963. #endif
  4964. strcpy(queuedata, message);
  4965. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4966. OCPP_insert_transaction_msg(YES, queuedata);
  4967. return result;
  4968. }
  4969. int sendStatusNotificationRequest(int gun_index)
  4970. {
  4971. mtrace();
  4972. int result = FAIL;
  4973. char message[600]={0};
  4974. char guid[37];
  4975. int currentStatus = 0;
  4976. struct timeval tmnow;
  4977. struct tm *tm;
  4978. char buf[28];//, usec_buf[6];
  4979. char tempdata[65]={0};
  4980. int tempIndex = 0;
  4981. uint8_t isStateChanged = TRUE;
  4982. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4983. gettimeofday(&tmnow, NULL);
  4984. time_t t;
  4985. t = time(NULL);
  4986. /*UTC time and date*/
  4987. tm = gmtime(&t);
  4988. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4989. #if 0 // remove temporally
  4990. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4991. strcat(buf,".");
  4992. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4993. strcat(buf,usec_buf);
  4994. #endif
  4995. //printf("%s",buf);
  4996. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4997. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4998. // it's option
  4999. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5000. /*
  5001. enum _SYSTEM_STATUS
  5002. {
  5003. S_BOOTING = 0,
  5004. S_IDLE, = 1
  5005. S_AUTHORIZING, =2
  5006. S_REASSIGN_CHECK, =3
  5007. S_REASSIGN, =4
  5008. S_PRECHARGE, =5
  5009. S_PREPARING_FOR_EV, =6
  5010. S_PREPARING_FOR_EVSE, =7
  5011. S_CHARGING, =8
  5012. S_TERMINATING, =9
  5013. S_COMPLETE, =10
  5014. S_ALARM, =11
  5015. S_FAULT =12
  5016. }
  5017. */
  5018. //check Transaction active
  5019. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5020. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5021. {
  5022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5023. {
  5024. tempIndex = ((gun_index==2) ? 1: 0);
  5025. }
  5026. else
  5027. {
  5028. tempIndex = gun_index;
  5029. }
  5030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5031. {
  5032. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5033. {
  5034. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5035. {
  5036. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5037. {
  5038. currentStatus = Preparing; //OCPP Status: Preparing
  5039. }
  5040. else
  5041. {
  5042. currentStatus = Available; //OCPP Status: Available
  5043. }
  5044. }
  5045. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5046. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5047. ) //S_PRECHARGE
  5048. {
  5049. currentStatus = Preparing; //OCPP Status: Preparing
  5050. }
  5051. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5052. {
  5053. currentStatus = Charging; //OCPP Status: Charging
  5054. }
  5055. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5056. {
  5057. currentStatus = Finishing; //OCPP Status: Finishing
  5058. }
  5059. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5060. {
  5061. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5062. }
  5063. 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
  5064. {
  5065. currentStatus = Unavailable; //OCPP Status: Unavailable
  5066. }
  5067. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5068. {
  5069. currentStatus = Faulted; //OCPP Status: Faulted
  5070. }
  5071. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5072. {
  5073. currentStatus = Reserved; //OCPP Status: Reserved
  5074. }
  5075. } //end of the same index
  5076. }//end of for CHAdeMO_QUANTITY
  5077. }
  5078. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5081. {
  5082. tempIndex = ((gun_index==2) ? 1: 0);
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < CCS_QUANTITY; index++)
  5089. {
  5090. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5091. {
  5092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5093. {
  5094. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5095. {
  5096. currentStatus = Preparing; //OCPP Status: Preparing
  5097. }
  5098. else
  5099. {
  5100. currentStatus = Available; //OCPP Status: Available
  5101. }
  5102. }
  5103. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5104. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5105. ) //S_PRECHARGE
  5106. {
  5107. currentStatus = Preparing; //OCPP Status: Preparing
  5108. }
  5109. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5110. {
  5111. currentStatus = Charging; //OCPP Status: Charging
  5112. }
  5113. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5114. {
  5115. currentStatus = Finishing; //OCPP Status: Finishing
  5116. }
  5117. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5118. {
  5119. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5120. }
  5121. 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
  5122. {
  5123. currentStatus = Unavailable; //OCPP Status : Unavailable
  5124. }
  5125. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5126. {
  5127. currentStatus = Faulted; //OCPP Status: Faulted
  5128. }
  5129. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5130. {
  5131. currentStatus = Reserved; //OCPP Status: Reserved
  5132. }
  5133. } //end of the same index
  5134. } // end of for CCS_QUANTITY
  5135. }
  5136. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5137. {
  5138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5139. {
  5140. tempIndex = ((gun_index==2) ? 1: 0);
  5141. }
  5142. else
  5143. {
  5144. tempIndex = gun_index;
  5145. }
  5146. for (int index = 0; index < GB_QUANTITY; index++)
  5147. {
  5148. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5151. {
  5152. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5153. {
  5154. currentStatus = Preparing; //OCPP Status: Preparing
  5155. }
  5156. else
  5157. {
  5158. currentStatus = Available; //OCPP Status: Available
  5159. }
  5160. }
  5161. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5162. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5163. ) //S_PRECHARGE
  5164. {
  5165. currentStatus = Preparing; //OCPP Status: Preparing
  5166. }
  5167. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5168. {
  5169. currentStatus = Charging; //OCPP Status: Charging
  5170. }
  5171. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5172. {
  5173. currentStatus = Finishing; //OCPP Status: Finishing
  5174. }
  5175. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5176. {
  5177. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5178. }
  5179. 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
  5180. {
  5181. currentStatus = Unavailable; //OCPP Status: Unavailable
  5182. }
  5183. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5184. {
  5185. currentStatus = Faulted; //OCPP Status: Faulted
  5186. }
  5187. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5188. {
  5189. currentStatus = Reserved; //OCPP Status: Reserved
  5190. }
  5191. } //end of the same index
  5192. } // end of for GB_QUANTITY
  5193. }
  5194. else if(gunType[gun_index] == GUN_TYPE_DO)
  5195. {
  5196. tempIndex = gun_index;
  5197. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5198. {
  5199. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5200. {
  5201. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5202. {
  5203. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5204. {
  5205. currentStatus = Preparing; //OCPP Status: Preparing
  5206. }
  5207. else
  5208. {
  5209. currentStatus = Available; //OCPP Status: Available
  5210. }
  5211. }
  5212. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5213. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5214. ) //S_PRECHARGE
  5215. {
  5216. currentStatus = Preparing; //OCPP Status: Preparing
  5217. }
  5218. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5219. {
  5220. currentStatus = Charging; //OCPP Status: Charging
  5221. }
  5222. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5223. {
  5224. currentStatus = Finishing; //OCPP Status: Finishing
  5225. }
  5226. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5227. {
  5228. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5229. }
  5230. 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
  5231. {
  5232. currentStatus = Unavailable; //OCPP Status: Unavailable
  5233. }
  5234. 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
  5235. {
  5236. currentStatus = Faulted; //OCPP Status: Faulted
  5237. }
  5238. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5239. {
  5240. currentStatus = Reserved; //OCPP Status: Reserved
  5241. }
  5242. } //end of the same index
  5243. }
  5244. }
  5245. else
  5246. {
  5247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5248. {
  5249. tempIndex = 2;
  5250. }
  5251. else
  5252. {
  5253. tempIndex = gun_index;
  5254. }
  5255. for (int index = 0; index < AC_QUANTITY; index++)
  5256. {
  5257. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5258. {
  5259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5260. {
  5261. 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))
  5262. {
  5263. currentStatus = Preparing; //OCPP Status: Preparing
  5264. }
  5265. else
  5266. {
  5267. currentStatus = Available; //OCPP Status: Available
  5268. }
  5269. }
  5270. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5271. {
  5272. currentStatus = Preparing; //OCPP Status: Preparing
  5273. }
  5274. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5275. {
  5276. currentStatus = Charging; //OCPP Status: Charging
  5277. }
  5278. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5279. {
  5280. currentStatus = Finishing; //OCPP Status: Finishing
  5281. }
  5282. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5283. {
  5284. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5285. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5286. else
  5287. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5288. }
  5289. 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
  5290. {
  5291. currentStatus = Unavailable; //OCPP Status: Unavailable
  5292. }
  5293. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5294. {
  5295. currentStatus = Faulted; //OCPP Status: Faulted
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5298. {
  5299. currentStatus = Reserved; //OCPP Status: Reserved
  5300. }
  5301. }//end of the same index
  5302. }//end of for AC_QUANTITY
  5303. }
  5304. //it's option
  5305. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5306. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5307. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5308. {
  5309. isStateChanged = FALSE;
  5310. }
  5311. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5312. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5313. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5314. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5315. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5316. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5317. random_uuid(guid);
  5318. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5319. , MESSAGE_TYPE_CALL
  5320. , guid
  5321. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5322. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5323. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5324. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5325. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5328. if((server_sign == TRUE) && isStateChanged)
  5329. {
  5330. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5331. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5332. LWS_Send(message);
  5333. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5334. 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*/)
  5335. {
  5336. //DEBUG_ERROR("statusNotification mapitem pass");
  5337. result = PASS;
  5338. }
  5339. }
  5340. else
  5341. {
  5342. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5343. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5344. result = PASS;
  5345. }
  5346. return result;
  5347. }
  5348. int sendStopTransactionRequest(int gun_index)
  5349. {
  5350. mtrace();
  5351. int result = FAIL;
  5352. //char message[1500]={0};
  5353. char guid[37]={0};
  5354. char tempdata[65]={0};
  5355. int tempIndex = 0;
  5356. char TempStopTransaction[256];
  5357. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5358. //int idx_sample=0;
  5359. DEBUG_INFO("sendStopTransactionRequest \n");
  5360. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5361. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5362. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5363. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5364. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5365. {
  5366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5367. {
  5368. tempIndex = ((gun_index==2) ? 1: 0);
  5369. }
  5370. else
  5371. {
  5372. tempIndex = gun_index;
  5373. }
  5374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5375. {
  5376. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5377. {
  5378. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5379. }
  5380. }// END OF CHAdeMO_QUANTITY
  5381. }
  5382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5383. {
  5384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5385. {
  5386. tempIndex = ((gun_index==2) ? 1: 0);
  5387. }
  5388. else
  5389. {
  5390. tempIndex = gun_index;
  5391. }
  5392. for (int index = 0; index < CCS_QUANTITY; index++)
  5393. {
  5394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5395. {
  5396. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5397. }
  5398. }// END OF CCS_QUANTITY
  5399. }
  5400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5401. {
  5402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5403. {
  5404. tempIndex = ((gun_index==2) ? 1: 0);
  5405. }
  5406. else
  5407. {
  5408. tempIndex = gun_index;
  5409. }
  5410. for (int index = 0; index < GB_QUANTITY; index++)
  5411. {
  5412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5413. {
  5414. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5415. }
  5416. }// END OF GB_QUANTITY
  5417. }
  5418. else if(gunType[gun_index] == GUN_TYPE_DO)
  5419. {
  5420. tempIndex = gun_index;
  5421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5424. {
  5425. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5426. }
  5427. }// END OF GB_QUANTITY
  5428. }
  5429. else
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5432. {
  5433. tempIndex = 2;
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5442. {
  5443. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5444. }
  5445. }// END OF AC_QUANTITY
  5446. }
  5447. //====================================== Stop Transaction Time =====================================================
  5448. struct timeval tmnow;
  5449. struct tm *tm;
  5450. char buf[28];//, usec_buf[6];
  5451. gettimeofday(&tmnow, NULL);
  5452. time_t t;
  5453. t = time(NULL);
  5454. /*UTC time and date*/
  5455. tm = gmtime(&t);
  5456. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5458. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5459. random_uuid(guid);
  5460. /***********************************transactionData******************************************************/
  5461. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5463. //=================================
  5464. // Transaction_Begin
  5465. //=================================
  5466. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5467. {
  5468. //============================================ Energy.Active.Import.Interval ================================
  5469. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5470. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5472. 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*/]);
  5473. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5474. 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))
  5475. {
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5477. }
  5478. else
  5479. {
  5480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5481. }
  5482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5484. }
  5485. //=================================
  5486. // Transaction_End
  5487. //=================================
  5488. // ================================= Current.Import L1 ===============================================
  5489. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5490. {
  5491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5492. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5493. {
  5494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5495. {
  5496. tempIndex = ((gun_index==2) ? 1: 0);
  5497. }
  5498. else
  5499. {
  5500. tempIndex = gun_index;
  5501. }
  5502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5503. {
  5504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5505. {
  5506. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5507. }
  5508. }// End of for CHAdeMO_QUANTITY
  5509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5510. }
  5511. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5512. {
  5513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5514. {
  5515. tempIndex = ((gun_index==2) ? 1: 0);
  5516. }
  5517. else
  5518. {
  5519. tempIndex = gun_index;
  5520. }
  5521. for (int index = 0; index < CCS_QUANTITY; index++)
  5522. {
  5523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5524. {
  5525. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5526. }
  5527. }// End of for CCS_QUANTITY
  5528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5529. }
  5530. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5531. {
  5532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5533. {
  5534. tempIndex = ((gun_index==2) ? 1: 0);
  5535. }
  5536. else
  5537. {
  5538. tempIndex = gun_index;
  5539. }
  5540. for (int index = 0; index < GB_QUANTITY; index++)
  5541. {
  5542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5543. {
  5544. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5545. }
  5546. }// End of for GB_QUANTITY
  5547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5548. }
  5549. else if(gunType[gun_index] == GUN_TYPE_DO)
  5550. {
  5551. tempIndex = gun_index;
  5552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5553. {
  5554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5555. {
  5556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5557. }
  5558. }
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5560. }
  5561. else
  5562. {
  5563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5564. {
  5565. tempIndex = 2;
  5566. }
  5567. else
  5568. {
  5569. tempIndex = gun_index;
  5570. }
  5571. for (int index = 0; index < AC_QUANTITY; index++)
  5572. {
  5573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5574. {
  5575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5576. }
  5577. }// End of for AC_QUANTITY
  5578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5579. }
  5580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5585. }
  5586. // ================================= Energy.Active.Import.Interval ==============================================
  5587. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5588. {
  5589. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5590. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5593. {
  5594. tempIndex = ((gun_index==2) ? 1: 0);
  5595. }
  5596. else
  5597. {
  5598. tempIndex = gun_index;
  5599. }
  5600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5601. {
  5602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5603. {
  5604. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5605. }
  5606. }// END OF CHAdeMO_QUANTITY
  5607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5610. {
  5611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5612. {
  5613. tempIndex = ((gun_index==2) ? 1: 0);
  5614. }
  5615. else
  5616. {
  5617. tempIndex = gun_index;
  5618. }
  5619. for (int index = 0; index < CCS_QUANTITY; index++)
  5620. {
  5621. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5622. {
  5623. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5624. }
  5625. }// END OF CCS_QUANTITY
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5627. }
  5628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5631. {
  5632. tempIndex = ((gun_index==2) ? 1: 0);
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < GB_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5641. {
  5642. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5643. }
  5644. }// END OF GB_QUANTITY
  5645. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5646. }
  5647. else if(gunType[gun_index] == GUN_TYPE_DO)
  5648. {
  5649. tempIndex = gun_index;
  5650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5651. {
  5652. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5653. {
  5654. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5655. }
  5656. }
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5658. }
  5659. else
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5662. {
  5663. tempIndex = 2;
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < AC_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5672. {
  5673. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5674. }
  5675. }// END OF AC_QUANTITY
  5676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5677. }
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5683. }
  5684. //=================================== Power.Active.Import ==================================================
  5685. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5686. {
  5687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5703. }
  5704. } // End for CHAdeMO_QUANTITY
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5706. }
  5707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5708. {
  5709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5710. {
  5711. tempIndex = ((gun_index==2) ? 1: 0);
  5712. }
  5713. else
  5714. {
  5715. tempIndex = gun_index;
  5716. }
  5717. for (int index = 0; index < CCS_QUANTITY; index++)
  5718. {
  5719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5720. {
  5721. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5722. }
  5723. } // END for CCS_QUANTITY
  5724. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5725. }
  5726. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5727. {
  5728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5729. {
  5730. tempIndex = ((gun_index==2) ? 1: 0);
  5731. }
  5732. else
  5733. {
  5734. tempIndex = gun_index;
  5735. }
  5736. for (int index = 0; index < GB_QUANTITY; index++)
  5737. {
  5738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5739. {
  5740. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5741. }
  5742. }// END for GB_QUANTITY
  5743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5744. }
  5745. else if(gunType[gun_index] == GUN_TYPE_DO)
  5746. {
  5747. tempIndex = gun_index;
  5748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5749. {
  5750. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5751. {
  5752. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5753. }
  5754. }
  5755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5756. }
  5757. else
  5758. {
  5759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5760. {
  5761. tempIndex = 2;
  5762. }
  5763. else
  5764. {
  5765. tempIndex = gun_index;
  5766. }
  5767. for (int index = 0; index < AC_QUANTITY; index++)
  5768. {
  5769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5770. {
  5771. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5772. }
  5773. } // END for AC_QUANTITY
  5774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5775. }
  5776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5777. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5781. }
  5782. //============================ Voltage L1 ====================================
  5783. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5784. {
  5785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5787. {
  5788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5789. {
  5790. tempIndex = ((gun_index==2) ? 1: 0);
  5791. }
  5792. else
  5793. {
  5794. tempIndex = gun_index;
  5795. }
  5796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5797. {
  5798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5799. {
  5800. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5801. }
  5802. } // END OF FOR CHAdeMO_QUANTITY
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5804. }
  5805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5806. {
  5807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5808. {
  5809. tempIndex = ((gun_index==2) ? 1: 0);
  5810. }
  5811. else
  5812. {
  5813. tempIndex = gun_index;
  5814. }
  5815. for (int index = 0; index < CCS_QUANTITY; index++)
  5816. {
  5817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5818. {
  5819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5820. }
  5821. } // END OF FOR CCS_QUANTITY
  5822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5823. }
  5824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5825. {
  5826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5827. {
  5828. tempIndex = ((gun_index==2) ? 1: 0);
  5829. }
  5830. else
  5831. {
  5832. tempIndex = gun_index;
  5833. }
  5834. for (int index = 0; index < GB_QUANTITY; index++)
  5835. {
  5836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5837. {
  5838. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5839. }
  5840. } // END OF FOR GB_QUANTITY
  5841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5842. }
  5843. else if(gunType[gun_index] == GUN_TYPE_DO)
  5844. {
  5845. tempIndex = gun_index;
  5846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5851. }
  5852. }
  5853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5854. }
  5855. else
  5856. {
  5857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5858. {
  5859. tempIndex = 2;
  5860. }
  5861. else
  5862. {
  5863. tempIndex = gun_index;
  5864. }
  5865. for (int index = 0; index < AC_QUANTITY; index++)
  5866. {
  5867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5868. {
  5869. 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
  5870. }
  5871. } // END OF FOR AC_QUANTITY
  5872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5873. }
  5874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5875. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5879. }
  5880. //====================== End SoC ================================
  5881. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5882. {
  5883. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5884. 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))
  5885. {
  5886. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5887. {
  5888. tempIndex = ((gun_index==2) ? 1: 0);
  5889. }
  5890. else
  5891. {
  5892. tempIndex = gun_index;
  5893. }
  5894. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5895. {
  5896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5897. {
  5898. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5899. {
  5900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5901. }
  5902. }
  5903. }
  5904. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5905. {
  5906. for (int index = 0; index < CCS_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5909. {
  5910. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5911. }
  5912. }
  5913. }
  5914. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5915. {
  5916. for (int index = 0; index < GB_QUANTITY; index++)
  5917. {
  5918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5919. {
  5920. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5921. }
  5922. }
  5923. }
  5924. else if(gunType[gun_index] == GUN_TYPE_DO)
  5925. {
  5926. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5927. {
  5928. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5929. {
  5930. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5931. }
  5932. }
  5933. }
  5934. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5935. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5940. } // END FOR DC CASE
  5941. }
  5942. // ================================= Current.Import L2 ===============================================
  5943. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5944. {
  5945. // AC 3 phse L2 current
  5946. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5947. {
  5948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5949. {
  5950. tempIndex = 2;
  5951. }
  5952. else
  5953. {
  5954. tempIndex = gun_index;
  5955. }
  5956. for (int index = 0; index < AC_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5959. {
  5960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5961. }
  5962. }// End of for AC_QUANTITY
  5963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5964. }
  5965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5970. }
  5971. // ================================= Current.Import L3 ===============================================
  5972. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5973. {
  5974. // AC 3 phse L3 current
  5975. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5976. {
  5977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5978. {
  5979. tempIndex = 2;
  5980. }
  5981. else
  5982. {
  5983. tempIndex = gun_index;
  5984. }
  5985. for (int index = 0; index < AC_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5988. {
  5989. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5990. }
  5991. }// End of for AC_QUANTITY
  5992. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5993. }
  5994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5999. }
  6000. //============================ Voltage L2 ====================================
  6001. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6002. {
  6003. // AC 3 phse L2 voltage
  6004. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6005. {
  6006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6007. {
  6008. tempIndex = 2;
  6009. }
  6010. else
  6011. {
  6012. tempIndex = gun_index;
  6013. }
  6014. for (int index = 0; index < AC_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6017. {
  6018. 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
  6019. }
  6020. } // END OF FOR AC_QUANTITY
  6021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6022. }
  6023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6028. }
  6029. //============================ Voltage L3 ====================================
  6030. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6031. {
  6032. // AC 3 phse L3 voltage
  6033. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6034. {
  6035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6036. {
  6037. tempIndex = 2;
  6038. }
  6039. else
  6040. {
  6041. tempIndex = gun_index;
  6042. }
  6043. for (int index = 0; index < AC_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6046. {
  6047. 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
  6048. }
  6049. } // END OF FOR AC_QUANTITY
  6050. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6051. }
  6052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6057. }
  6058. //====================== Start SoC ================================
  6059. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6060. {
  6061. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6062. 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))
  6063. {
  6064. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6065. {
  6066. tempIndex = ((gun_index==2) ? 1: 0);
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6073. {
  6074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6079. }
  6080. }
  6081. }
  6082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6083. {
  6084. for (int index = 0; index < CCS_QUANTITY; index++)
  6085. {
  6086. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6087. {
  6088. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6089. }
  6090. }
  6091. }
  6092. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6093. {
  6094. for (int index = 0; index < GB_QUANTITY; index++)
  6095. {
  6096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6097. {
  6098. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6099. }
  6100. }
  6101. }
  6102. else if(gunType[gun_index] == GUN_TYPE_DO)
  6103. {
  6104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6105. {
  6106. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6107. {
  6108. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6109. }
  6110. }
  6111. }
  6112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6118. } // END FOR DC CASE
  6119. }
  6120. //================================================ Message create ====================================================
  6121. json_object *StopTransaction = json_object_new_object();
  6122. json_object *transactionDatas = json_object_new_array();
  6123. json_object *sampledValues = json_object_new_array();
  6124. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6125. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6126. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6127. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6128. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6129. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6130. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6131. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6132. {
  6133. json_object *transactionData = json_object_new_object();
  6134. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6135. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6136. {
  6137. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6138. {
  6139. json_object *sampledValue = json_object_new_object();
  6140. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6141. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6142. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6143. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6144. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6145. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6146. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6147. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6148. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6149. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6150. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6151. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6152. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6153. json_object_array_add(sampledValues, sampledValue);
  6154. }
  6155. }
  6156. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6157. json_object_array_add(transactionDatas, transactionData);
  6158. }
  6159. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6160. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6161. ,MESSAGE_TYPE_CALL
  6162. ,guid
  6163. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6164. json_object_put(StopTransaction);
  6165. #if 1 // for TempStopTransaction
  6166. //Delete TempStopTransaction
  6167. if((access(TempStopTransaction,F_OK))!=-1)
  6168. {
  6169. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6170. }
  6171. #endif
  6172. #if 1
  6173. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6174. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6175. {
  6176. result = PASS;
  6177. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6178. }
  6179. #endif
  6180. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6181. OCPP_insert_transaction_msg(NO, queuedata);
  6182. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6183. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6184. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6185. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6186. {
  6187. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6188. }
  6189. //for test
  6190. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6191. return result;
  6192. }
  6193. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6194. {
  6195. mtrace();
  6196. int result = FAIL;
  6197. char guid[37]={0};
  6198. char tempdata[65]={0};
  6199. int tempIndex = 0;
  6200. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6201. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6202. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6203. //set value
  6204. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6205. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6206. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6207. -1);
  6208. random_uuid(guid);
  6209. //UTC Date time
  6210. struct timeval tmnow;
  6211. struct tm *tm;
  6212. char buf[28];//, usec_buf[6];
  6213. gettimeofday(&tmnow, NULL);
  6214. time_t t;
  6215. t = time(NULL);
  6216. /*UTC time and date*/
  6217. tm = gmtime(&t);
  6218. if(dataType == ReadingContext_Sample_Clock)
  6219. {
  6220. struct tm *tmTarget;
  6221. struct timeb tbTarget;
  6222. tbTarget.time = mktime(tm);
  6223. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6224. tmTarget = gmtime(&tbTarget.time);
  6225. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6226. }
  6227. else
  6228. {
  6229. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6230. }
  6231. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6232. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6233. //********************************(1)Current.Import L1************************************************/
  6234. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6235. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6236. (dataType == ReadingContext_Trigger))
  6237. {
  6238. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6239. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6240. {
  6241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6242. {
  6243. tempIndex = ((gun_index==2) ? 1: 0);
  6244. }
  6245. else
  6246. {
  6247. tempIndex = gun_index;
  6248. }
  6249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6254. }
  6255. }
  6256. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6257. }
  6258. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6261. {
  6262. tempIndex = ((gun_index==2) ? 1: 0);
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < CCS_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6271. {
  6272. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6273. }
  6274. }
  6275. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6276. }
  6277. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6278. {
  6279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6280. {
  6281. tempIndex = ((gun_index==2) ? 1: 0);
  6282. }
  6283. else
  6284. {
  6285. tempIndex = gun_index;
  6286. }
  6287. for (int index = 0; index < GB_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6290. {
  6291. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6292. }
  6293. }
  6294. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6295. }
  6296. else if(gunType[gun_index] == GUN_TYPE_DO)
  6297. {
  6298. tempIndex = gun_index;
  6299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6307. }
  6308. else
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6311. {
  6312. tempIndex = 2;
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < AC_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6321. {
  6322. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6323. }
  6324. }
  6325. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6326. }
  6327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6328. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6329. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6332. }
  6333. //********************************(2)Energy.Active.Import.Register ************************************************/
  6334. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6335. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6336. (dataType == ReadingContext_Trigger))
  6337. {
  6338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6354. }
  6355. }
  6356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6357. }
  6358. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6359. {
  6360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6361. {
  6362. tempIndex = ((gun_index==2) ? 1: 0);
  6363. }
  6364. else
  6365. {
  6366. tempIndex = gun_index;
  6367. }
  6368. for (int index = 0; index < CCS_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6373. }
  6374. }
  6375. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6378. {
  6379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6380. {
  6381. tempIndex = ((gun_index==2) ? 1: 0);
  6382. }
  6383. else
  6384. {
  6385. tempIndex = gun_index;
  6386. }
  6387. for (int index = 0; index < GB_QUANTITY; index++)
  6388. {
  6389. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6390. {
  6391. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6392. }
  6393. }
  6394. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6395. }
  6396. else if(gunType[gun_index] == GUN_TYPE_DO)
  6397. {
  6398. tempIndex = gun_index;
  6399. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6402. {
  6403. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6404. }
  6405. }
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6407. }
  6408. else
  6409. {
  6410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6411. {
  6412. tempIndex = 2;
  6413. }
  6414. else
  6415. {
  6416. tempIndex = gun_index;
  6417. }
  6418. for (int index = 0; index < AC_QUANTITY; index++)
  6419. {
  6420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6421. {
  6422. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6423. }
  6424. }
  6425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6426. }
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6428. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6431. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6432. }
  6433. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6434. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6435. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6436. (dataType == ReadingContext_Trigger))
  6437. {
  6438. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6439. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6440. {
  6441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6442. {
  6443. tempIndex = ((gun_index==2) ? 1: 0);
  6444. }
  6445. else
  6446. {
  6447. tempIndex = gun_index;
  6448. }
  6449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6450. {
  6451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6452. {
  6453. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6454. }
  6455. } // END OF FOR CHAdeMO_QUANTITY
  6456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6457. }
  6458. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6459. {
  6460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6461. {
  6462. tempIndex = ((gun_index==2) ? 1: 0);
  6463. }
  6464. else
  6465. {
  6466. tempIndex = gun_index;
  6467. }
  6468. for (int index = 0; index < CCS_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6471. {
  6472. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6473. }
  6474. } // END OF CCS_QUANTITY
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6476. }
  6477. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6478. {
  6479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6480. {
  6481. tempIndex = ((gun_index==2) ? 1: 0);
  6482. }
  6483. else
  6484. {
  6485. tempIndex = gun_index;
  6486. }
  6487. for (int index = 0; index < GB_QUANTITY; index++)
  6488. {
  6489. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6490. {
  6491. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6492. }
  6493. } // END OF GB_QUANTITY
  6494. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6495. }
  6496. else if(gunType[gun_index] == GUN_TYPE_DO)
  6497. {
  6498. tempIndex = gun_index;
  6499. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6502. {
  6503. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6504. }
  6505. }
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6507. }
  6508. else
  6509. {
  6510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6511. {
  6512. tempIndex = 2;
  6513. }
  6514. else
  6515. {
  6516. tempIndex = gun_index;
  6517. }
  6518. for (int index = 0; index < AC_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6521. {
  6522. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6523. }
  6524. }
  6525. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6526. }
  6527. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6528. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6532. }
  6533. //********************************(4)Power.Active.Import************************************************/
  6534. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6535. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6536. (dataType == ReadingContext_Trigger))
  6537. {
  6538. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6539. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6540. {
  6541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6542. {
  6543. tempIndex = ((gun_index==2) ? 1: 0);
  6544. }
  6545. else
  6546. {
  6547. tempIndex = gun_index;
  6548. }
  6549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6552. {
  6553. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6554. }
  6555. } // END OF FOR
  6556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6557. }
  6558. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6559. {
  6560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6561. {
  6562. tempIndex = ((gun_index==2) ? 1: 0);
  6563. }
  6564. else
  6565. {
  6566. tempIndex = gun_index;
  6567. }
  6568. for (int index = 0; index < CCS_QUANTITY; index++)
  6569. {
  6570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6571. {
  6572. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6573. }
  6574. }
  6575. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6576. }
  6577. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6578. {
  6579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6580. {
  6581. tempIndex = ((gun_index==2) ? 1: 0);
  6582. }
  6583. else
  6584. {
  6585. tempIndex = gun_index;
  6586. }
  6587. for (int index = 0; index < GB_QUANTITY; index++)
  6588. {
  6589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6590. {
  6591. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6592. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6593. }
  6594. }
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6596. }
  6597. else if(gunType[gun_index] == GUN_TYPE_DO)
  6598. {
  6599. tempIndex = gun_index;
  6600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6603. {
  6604. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6605. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6606. }
  6607. }
  6608. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6609. }
  6610. else
  6611. {
  6612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6613. {
  6614. tempIndex = 2;
  6615. }
  6616. else
  6617. {
  6618. tempIndex = gun_index;
  6619. }
  6620. for (int index = 0; index < AC_QUANTITY; index++)
  6621. {
  6622. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6623. {
  6624. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6625. }
  6626. }
  6627. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6628. }
  6629. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6630. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6632. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6633. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6634. }
  6635. //***********************************************(5)VOLTAGE L1******************************************************/
  6636. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6637. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6638. (dataType == ReadingContext_Trigger))
  6639. {
  6640. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6641. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6642. {
  6643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6644. {
  6645. tempIndex = ((gun_index==2) ? 1: 0);
  6646. }
  6647. else
  6648. {
  6649. tempIndex = gun_index;
  6650. }
  6651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6652. {
  6653. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6654. {
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6656. }
  6657. }
  6658. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6659. }
  6660. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6663. {
  6664. tempIndex = ((gun_index==2) ? 1: 0);
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < CCS_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6673. {
  6674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6675. }
  6676. }
  6677. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6678. }
  6679. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6680. {
  6681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6682. {
  6683. tempIndex = ((gun_index==2) ? 1: 0);
  6684. }
  6685. else
  6686. {
  6687. tempIndex = gun_index;
  6688. }
  6689. for (int index = 0; index < GB_QUANTITY; index++)
  6690. {
  6691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6692. {
  6693. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6694. }
  6695. }
  6696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6697. }
  6698. else if(gunType[gun_index] == GUN_TYPE_DO)
  6699. {
  6700. tempIndex = gun_index;
  6701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6702. {
  6703. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6704. {
  6705. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6706. }
  6707. }
  6708. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6709. }
  6710. else
  6711. {
  6712. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6713. {
  6714. tempIndex = 2;
  6715. }
  6716. else
  6717. {
  6718. tempIndex = gun_index;
  6719. }
  6720. for (int index = 0; index < AC_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6723. {
  6724. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6725. }
  6726. }
  6727. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6728. }
  6729. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6730. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6731. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6732. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6733. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6734. }
  6735. //***********************************************(6)SOC******************************************************/
  6736. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6737. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6738. (dataType == ReadingContext_Trigger))
  6739. {
  6740. 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))
  6741. {
  6742. //idx_sample=5;
  6743. //sampledValue = NULL;
  6744. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6745. {
  6746. tempIndex = ((gun_index==2) ? 1: 0);
  6747. }
  6748. else
  6749. {
  6750. tempIndex = gun_index;
  6751. }
  6752. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6753. {
  6754. //tempIndex = ((gun_index==2) ? 1: 0);
  6755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6758. {
  6759. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6760. }
  6761. }
  6762. }
  6763. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6764. {
  6765. //tempIndex = ((gun_index==2) ? 1: 0);
  6766. for (int index = 0; index < CCS_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6769. {
  6770. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6771. }
  6772. }
  6773. }
  6774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6775. {
  6776. //tempIndex = ((gun_index==2) ? 1: 0);
  6777. for (int index = 0; index < GB_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6780. {
  6781. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6782. }
  6783. }
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_DO)
  6786. {
  6787. //tempIndex = ((gun_index==2) ? 1: 0);
  6788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6789. {
  6790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6791. {
  6792. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6793. }
  6794. }
  6795. }
  6796. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6797. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6798. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6802. }
  6803. }
  6804. //********************************(7)Current.Import L2************************************************/
  6805. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6806. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6807. (dataType == ReadingContext_Trigger))
  6808. {
  6809. // Only for AC 3 phase
  6810. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6811. {
  6812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6813. {
  6814. tempIndex = 2;
  6815. }
  6816. else
  6817. {
  6818. tempIndex = gun_index;
  6819. }
  6820. for (int index = 0; index < AC_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6823. {
  6824. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6825. }
  6826. }
  6827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6828. }
  6829. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6830. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6831. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6833. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6834. }
  6835. //********************************(8)Current.Import L3************************************************/
  6836. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6837. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6838. (dataType == ReadingContext_Trigger))
  6839. {
  6840. // Only for AC 3 phase
  6841. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6842. {
  6843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6844. {
  6845. tempIndex = 2;
  6846. }
  6847. else
  6848. {
  6849. tempIndex = gun_index;
  6850. }
  6851. for (int index = 0; index < AC_QUANTITY; index++)
  6852. {
  6853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6854. {
  6855. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6856. }
  6857. }
  6858. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6859. }
  6860. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6861. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6862. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6864. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6865. }
  6866. //***********************************************(9)VOLTAGE L2******************************************************/
  6867. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6868. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6869. (dataType == ReadingContext_Trigger))
  6870. {
  6871. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6872. {
  6873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6874. {
  6875. tempIndex = 2;
  6876. }
  6877. else
  6878. {
  6879. tempIndex = gun_index;
  6880. }
  6881. for (int index = 0; index < AC_QUANTITY; index++)
  6882. {
  6883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6884. {
  6885. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6886. }
  6887. }
  6888. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6889. }
  6890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6895. }
  6896. //***********************************************(10)VOLTAGE L3******************************************************/
  6897. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6898. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6899. (dataType == ReadingContext_Trigger))
  6900. {
  6901. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6902. {
  6903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6904. {
  6905. tempIndex = 2;
  6906. }
  6907. else
  6908. {
  6909. tempIndex = gun_index;
  6910. }
  6911. for (int index = 0; index < AC_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6919. }
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6925. }
  6926. //***********************************************(11)Current.Offered******************************************************/
  6927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6929. (dataType == ReadingContext_Trigger))
  6930. {
  6931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6933. {
  6934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6935. {
  6936. tempIndex = ((gun_index==2) ? 1: 0);
  6937. }
  6938. else
  6939. {
  6940. tempIndex = gun_index;
  6941. }
  6942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6947. }
  6948. } // END OF FOR CHAdeMO_QUANTITY
  6949. }
  6950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6951. {
  6952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6953. {
  6954. tempIndex = ((gun_index==2) ? 1: 0);
  6955. }
  6956. else
  6957. {
  6958. tempIndex = gun_index;
  6959. }
  6960. for (int index = 0; index < CCS_QUANTITY; index++)
  6961. {
  6962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6963. {
  6964. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6965. }
  6966. } // END OF CCS_QUANTITY
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6969. {
  6970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6971. {
  6972. tempIndex = ((gun_index==2) ? 1: 0);
  6973. }
  6974. else
  6975. {
  6976. tempIndex = gun_index;
  6977. }
  6978. for (int index = 0; index < GB_QUANTITY; index++)
  6979. {
  6980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6981. {
  6982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6983. }
  6984. } // END OF GB_QUANTITY
  6985. }
  6986. else if(gunType[gun_index] == GUN_TYPE_DO)
  6987. {
  6988. tempIndex = gun_index;
  6989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6990. {
  6991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6992. {
  6993. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6994. }
  6995. }
  6996. }
  6997. else
  6998. {
  6999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7000. {
  7001. tempIndex = 2;
  7002. }
  7003. else
  7004. {
  7005. tempIndex = gun_index;
  7006. }
  7007. for (int index = 0; index < AC_QUANTITY; index++)
  7008. {
  7009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7010. {
  7011. uint16_t currentOffer;
  7012. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7013. {
  7014. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7015. }
  7016. else
  7017. {
  7018. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7019. }
  7020. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7021. }
  7022. }
  7023. }
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7029. }
  7030. //***********************************************(12)Power.Offered******************************************************/
  7031. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7032. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7033. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7034. {
  7035. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7036. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7037. {
  7038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7039. {
  7040. tempIndex = ((gun_index==2) ? 1: 0);
  7041. }
  7042. else
  7043. {
  7044. tempIndex = gun_index;
  7045. }
  7046. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7049. {
  7050. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7051. }
  7052. } // END OF FOR CHAdeMO_QUANTITY
  7053. }
  7054. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7055. {
  7056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7057. {
  7058. tempIndex = ((gun_index==2) ? 1: 0);
  7059. }
  7060. else
  7061. {
  7062. tempIndex = gun_index;
  7063. }
  7064. for (int index = 0; index < CCS_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7069. }
  7070. } // END OF CCS_QUANTITY
  7071. }
  7072. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7073. {
  7074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7075. {
  7076. tempIndex = ((gun_index==2) ? 1: 0);
  7077. }
  7078. else
  7079. {
  7080. tempIndex = gun_index;
  7081. }
  7082. for (int index = 0; index < GB_QUANTITY; index++)
  7083. {
  7084. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7085. {
  7086. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7087. }
  7088. } // END OF GB_QUANTITY
  7089. }
  7090. else if(gunType[gun_index] == GUN_TYPE_DO)
  7091. {
  7092. tempIndex = gun_index;
  7093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7094. {
  7095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7096. {
  7097. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7098. }
  7099. }
  7100. }
  7101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7102. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7106. }
  7107. // Message create ====================================================================================================
  7108. if(TRUE)
  7109. {
  7110. json_object *MeterValueReq = json_object_new_object();
  7111. json_object *MeterValues = json_object_new_array();
  7112. json_object *sampledValues = json_object_new_array();
  7113. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7114. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7115. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7116. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7117. {
  7118. json_object *MeterValue = json_object_new_object();
  7119. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7120. {
  7121. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7122. {
  7123. json_object *sampledValue = json_object_new_object();
  7124. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7125. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7126. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7127. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7128. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7129. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7130. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7131. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7132. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7133. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7134. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7135. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7136. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7137. json_object_array_add(sampledValues, sampledValue);
  7138. }
  7139. }
  7140. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7141. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7142. json_object_array_add(MeterValues, MeterValue);
  7143. }
  7144. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7145. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7146. ,gun_index + 1
  7147. ,MESSAGE_TYPE_CALL
  7148. ,guid
  7149. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7150. json_object_put(MeterValueReq);
  7151. }
  7152. // Put request guid to hash map
  7153. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7154. 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*/)
  7155. {
  7156. result = PASS;
  7157. //DEBUG_INFO("MeterValues mapitem pass\n");
  7158. }
  7159. if((dataType != ReadingContext_Trigger) &&
  7160. (dataType != ReadingContext_Sample_Clock) &&
  7161. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7162. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7163. else
  7164. {
  7165. if(FirstHeartBeat)
  7166. LWS_Send(queuedata +2);
  7167. }
  7168. return result;
  7169. }
  7170. int sendLogStatusNotificationRequest(char *status)
  7171. {
  7172. mtrace();
  7173. int result = PASS;
  7174. char message[4096]={0};
  7175. char guid[37]={0};
  7176. char tempdata[128]={0};
  7177. json_object *LogStatusNotification = json_object_new_object();
  7178. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7179. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7180. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7181. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7182. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7183. random_uuid(guid);
  7184. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7185. json_object_put(LogStatusNotification);
  7186. LWS_Send(message);
  7187. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7188. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7189. {
  7190. result = PASS;
  7191. }
  7192. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7193. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7194. return result;
  7195. }
  7196. int sendSecurityEventNotificationRequest()
  7197. {
  7198. mtrace();
  7199. int result = PASS;
  7200. char message[4096]={0};
  7201. char guid[37]={0};
  7202. char tempdata[128]={0};
  7203. json_object *SecurityEventNotification = json_object_new_object();
  7204. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7205. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7206. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7207. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7208. random_uuid(guid);
  7209. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7210. json_object_put(SecurityEventNotification);
  7211. LWS_Send(message);
  7212. sprintf(tempdata, "SecurityEventNotification,0");
  7213. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7214. {
  7215. result = PASS;
  7216. }
  7217. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7218. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7219. return result;
  7220. }
  7221. int sendSignCertificateRequest()
  7222. {
  7223. mtrace();
  7224. int result = PASS;
  7225. char message[4096]={0};
  7226. char guid[37]={0};
  7227. char tempdata[128]={0};
  7228. json_object *SignCertificate = json_object_new_object();
  7229. DEBUG_INFO("sendSignCertificateRequest...\n");
  7230. // Read csr file content
  7231. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7232. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7233. char *line = NULL;
  7234. size_t len = 0;
  7235. while(getline(&line, &len, fp) != -1)
  7236. {
  7237. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7238. {
  7239. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7240. }
  7241. }
  7242. fclose(fp);
  7243. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7244. random_uuid(guid);
  7245. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7246. json_object_put(SignCertificate);
  7247. LWS_Send(message);
  7248. sprintf(tempdata, "SignCertificate,0");
  7249. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7250. {
  7251. result = PASS;
  7252. }
  7253. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7254. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7255. return result;
  7256. }
  7257. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7258. {
  7259. mtrace();
  7260. int result = PASS;
  7261. char message[110]={0};
  7262. char guid[37]={0};
  7263. char tempdata[65]={0};
  7264. json_object *FirmwareStatusNotification = json_object_new_object();
  7265. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7266. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7267. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7268. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7269. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7270. random_uuid(guid);
  7271. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7272. json_object_put(FirmwareStatusNotification);
  7273. LWS_Send(message);
  7274. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7275. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7276. {
  7277. result = PASS;
  7278. }
  7279. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7280. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7281. return result;
  7282. }
  7283. //==========================================
  7284. // send confirm routine
  7285. //==========================================
  7286. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7287. {
  7288. mtrace();
  7289. int result = FAIL;
  7290. char message[100]={0};
  7291. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7292. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7293. LWS_Send(message);
  7294. result = TRUE;
  7295. return result;
  7296. }
  7297. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7298. {
  7299. mtrace();
  7300. int result = FAIL;
  7301. char message[100]={0};
  7302. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7304. LWS_Send(message);
  7305. result = TRUE;
  7306. return result;
  7307. }
  7308. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7309. {
  7310. mtrace();
  7311. int result = FAIL;
  7312. char message[100]={0};
  7313. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7314. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7315. LWS_Send(message);
  7316. result = TRUE;
  7317. return result;
  7318. }
  7319. int sendClearCacheConfirmation(char *uuid,char *payload)
  7320. {
  7321. mtrace();
  7322. int result = FAIL;
  7323. char message[500]={0};
  7324. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7325. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7326. LWS_Send(message);
  7327. return result;
  7328. }
  7329. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7330. {
  7331. mtrace();
  7332. int result = FAIL;
  7333. char message[500]={0};
  7334. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7335. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7336. LWS_Send(message);
  7337. return result;
  7338. }
  7339. int sendDataTransferConfirmation(char *uuid,char *payload)
  7340. {
  7341. mtrace();
  7342. char statusStr[20]={0};
  7343. char dataStr[10]={0};
  7344. char sstr[20]={0};
  7345. int c = 0;
  7346. char *loc;
  7347. int result = FAIL;
  7348. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7349. /**********************status**************************/
  7350. loc = strstr(payload, "status");
  7351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7352. c = 0;
  7353. while (loc[3+strlen("status")+c] != '\"')
  7354. {
  7355. sstr[c] = loc[3+strlen("status")+c];
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. strcpy(statusStr, sstr);
  7360. /**********************data**************************/
  7361. loc = strstr(payload, "data");
  7362. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7363. c = 0;
  7364. while (loc[3+strlen("data")+c] != '\"')
  7365. {
  7366. sstr[c] = loc[3+strlen("data")+c];
  7367. c++;
  7368. }
  7369. sstr[c] = '\0';
  7370. strcpy(dataStr, sstr);
  7371. return result;
  7372. }
  7373. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7374. {
  7375. mtrace();
  7376. int result = FAIL;
  7377. char message[1000]={0};
  7378. int CompositeScheduleIndex = 0;
  7379. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7380. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7381. if(nPeriod == 0)
  7382. {
  7383. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7384. {
  7385. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7386. ,MESSAGE_TYPE_CALLRESULT
  7387. ,uuid
  7388. ,payload
  7389. ,connectorIdInt);
  7390. }
  7391. else
  7392. {
  7393. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7394. ,MESSAGE_TYPE_CALLRESULT
  7395. ,uuid
  7396. ,payload
  7397. ,connectorIdInt
  7398. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7399. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7400. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7401. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7402. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7403. }
  7404. }
  7405. else
  7406. {
  7407. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7408. ,MESSAGE_TYPE_CALLRESULT
  7409. ,uuid
  7410. ,payload
  7411. ,connectorIdInt
  7412. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7413. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7414. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7415. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7416. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7417. {
  7418. if (idx_sample == 0)
  7419. {
  7420. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7421. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7422. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7423. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7424. }
  7425. else
  7426. {
  7427. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7428. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7429. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7430. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7431. }
  7432. }
  7433. sprintf(message + strlen(message), "]}}]");
  7434. }
  7435. LWS_Send(message);
  7436. result = TRUE;
  7437. return result;
  7438. }
  7439. int sendGetConfigurationConfirmation(char *uuid)
  7440. {
  7441. mtrace();
  7442. int result = FAIL;
  7443. int MaxKeySupported = 0;
  7444. int sentConfigurationNumber= 0;
  7445. int sentunConfigurationNumber= 0;
  7446. char message[1024*10]={0};
  7447. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7448. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7449. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7450. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7451. ,MESSAGE_TYPE_CALLRESULT
  7452. ,uuid );
  7453. //configuration key
  7454. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7455. {
  7456. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7457. {
  7458. if (sentConfigurationNumber == 0)
  7459. {
  7460. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7461. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7462. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7463. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7464. }
  7465. else
  7466. {
  7467. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7468. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7469. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7470. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7471. }
  7472. sentConfigurationNumber = sentConfigurationNumber + 1;
  7473. }
  7474. }
  7475. sprintf(message + strlen(message), "]");
  7476. if(UnknownKeynum != 0)
  7477. {
  7478. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7479. //unkown key
  7480. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7481. {
  7482. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7483. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7484. if(sentunConfigurationNumber == 0)
  7485. {
  7486. sprintf(message + strlen(message), "\"%s\""
  7487. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7488. }
  7489. else
  7490. {
  7491. sprintf(message + strlen(message), ",\"%s\""
  7492. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7493. }
  7494. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7495. }
  7496. sprintf(message + strlen(message), "]");
  7497. }
  7498. sprintf(message + strlen(message), "}]");
  7499. LWS_Send(message);
  7500. return result;
  7501. }
  7502. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7503. {
  7504. mtrace();
  7505. int result = FAIL;
  7506. char message[400]={0};
  7507. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7508. if(strcmp(payload,"")==0)
  7509. {
  7510. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7511. }
  7512. else
  7513. {
  7514. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7515. }
  7516. LWS_Send(message);
  7517. result = TRUE;
  7518. return result;
  7519. }
  7520. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7521. {
  7522. mtrace();
  7523. int result = FAIL;
  7524. char message[80]={0};
  7525. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7526. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7527. LWS_Send(message);
  7528. result = TRUE;
  7529. return result;
  7530. }
  7531. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7532. {
  7533. mtrace();
  7534. int result = FAIL;
  7535. char message[80]={0};
  7536. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7537. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7538. LWS_Send(message);
  7539. result = TRUE;
  7540. return result;
  7541. }
  7542. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7543. {
  7544. mtrace();
  7545. int result = FAIL;
  7546. char message[80]={0};
  7547. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7548. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7549. LWS_Send(message);
  7550. result = TRUE;
  7551. return result;
  7552. }
  7553. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7554. {
  7555. mtrace();
  7556. int result = FAIL;
  7557. char message[80]={0};
  7558. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7559. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7560. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7561. LWS_Send(message);
  7562. result = TRUE;
  7563. return result;
  7564. }
  7565. int sendResetConfirmation(char *uuid,char *payload)
  7566. {
  7567. mtrace();
  7568. int result = FAIL;
  7569. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7570. char message[80]={0};
  7571. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7572. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7573. LWS_Send(message);
  7574. result = TRUE;
  7575. return result;
  7576. }
  7577. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7578. {
  7579. mtrace();
  7580. int result = FAIL;
  7581. char message[500]={0};
  7582. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7583. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7584. LWS_Send(message);
  7585. result = TRUE;
  7586. return result;
  7587. }
  7588. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7589. {
  7590. mtrace();
  7591. int result = FAIL;
  7592. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7593. char message[80]={0};
  7594. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7595. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7596. LWS_Send(message);
  7597. result = TRUE;
  7598. return result;
  7599. }
  7600. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7601. {
  7602. mtrace();
  7603. int result = FAIL;
  7604. char message[80]={0};
  7605. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7606. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7607. LWS_Send(message);
  7608. result = TRUE;
  7609. return result;
  7610. }
  7611. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7612. {
  7613. mtrace();
  7614. int result = FAIL;
  7615. char message[80]={0};
  7616. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7617. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7618. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7619. LWS_Send(message);
  7620. result = TRUE;
  7621. return result;
  7622. }
  7623. int sendUpdateFirmwareConfirmation(char *uuid)
  7624. {
  7625. mtrace();
  7626. int result = FAIL;
  7627. char message[60]={0};
  7628. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7629. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7630. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7631. LWS_Send(message);
  7632. result = TRUE;
  7633. return result;
  7634. }
  7635. int sendCertificateSignedConfirmation(char *uuid)
  7636. {
  7637. mtrace();
  7638. int result = PASS;
  7639. char message[4096]={0};
  7640. json_object *CertificateSigned = json_object_new_object();
  7641. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7642. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7643. sprintf(message,"[%d,\"%s\",%s]"
  7644. ,MESSAGE_TYPE_CALLRESULT
  7645. ,uuid
  7646. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7647. json_object_put(CertificateSigned);
  7648. LWS_Send(message);
  7649. return result;
  7650. }
  7651. int sendDeleteCertificateConfirmation(char *uuid)
  7652. {
  7653. mtrace();
  7654. int result = PASS;
  7655. char message[4096]={0};
  7656. json_object *DeleteCertificate = json_object_new_object();
  7657. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7658. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7659. sprintf(message,"[%d,\"%s\",%s]"
  7660. ,MESSAGE_TYPE_CALLRESULT
  7661. ,uuid
  7662. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7663. json_object_put(DeleteCertificate);
  7664. LWS_Send(message);
  7665. return result;
  7666. }
  7667. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7668. {
  7669. mtrace();
  7670. int result = PASS;
  7671. char message[4096]={0};
  7672. json_object *ExtendedTriggerMessage = json_object_new_object();
  7673. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7674. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7675. sprintf(message,"[%d,\"%s\",%s]"
  7676. ,MESSAGE_TYPE_CALLRESULT
  7677. ,uuid
  7678. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7679. json_object_put(ExtendedTriggerMessage);
  7680. LWS_Send(message);
  7681. return result;
  7682. }
  7683. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7684. {
  7685. mtrace();
  7686. int result = PASS;
  7687. char message[4096]={0};
  7688. json_object *GetInstalledCertificateIds = json_object_new_object();
  7689. json_object *certificateHashDataDatas = json_object_new_array();
  7690. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7691. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7692. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7693. {
  7694. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7695. {
  7696. json_object *certificateHashData = json_object_new_object();
  7697. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7698. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7699. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7700. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7701. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7702. }
  7703. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7704. }
  7705. else
  7706. {
  7707. json_object_put(certificateHashDataDatas);
  7708. }
  7709. sprintf(message,"[%d,\"%s\",%s]"
  7710. ,MESSAGE_TYPE_CALLRESULT
  7711. ,uuid
  7712. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7713. json_object_put(GetInstalledCertificateIds);
  7714. LWS_Send(message);
  7715. return result;
  7716. }
  7717. int sendGetLogConfirmation(char *uuid)
  7718. {
  7719. mtrace();
  7720. int result = PASS;
  7721. char message[4096]={0};
  7722. json_object *GetLog = json_object_new_object();
  7723. DEBUG_INFO("sendGetLogConfirmation...\n");
  7724. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7725. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7726. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7727. sprintf(message,"[%d,\"%s\",%s]"
  7728. ,MESSAGE_TYPE_CALLRESULT
  7729. ,uuid
  7730. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7731. json_object_put(GetLog);
  7732. LWS_Send(message);
  7733. return result;
  7734. }
  7735. int sendInstallCertificateConfirmation(char *uuid)
  7736. {
  7737. mtrace();
  7738. int result = PASS;
  7739. char message[4096]={0};
  7740. json_object *InstallCertificate = json_object_new_object();
  7741. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7742. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7743. sprintf(message,"[%d,\"%s\",%s]"
  7744. ,MESSAGE_TYPE_CALLRESULT
  7745. ,uuid
  7746. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7747. json_object_put(InstallCertificate);
  7748. LWS_Send(message);
  7749. return result;
  7750. }
  7751. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7752. {
  7753. mtrace();
  7754. int result = PASS;
  7755. char message[4096]={0};
  7756. json_object *SignedUpdateFirmware = json_object_new_object();
  7757. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7758. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7759. sprintf(message,"[%d,\"%s\",%s]"
  7760. ,MESSAGE_TYPE_CALLRESULT
  7761. ,uuid
  7762. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7763. json_object_put(SignedUpdateFirmware);
  7764. LWS_Send(message);
  7765. return result;
  7766. }
  7767. int sendUnknownConfirmation(char *uuid)
  7768. {
  7769. mtrace();
  7770. int result = PASS;
  7771. char message[256]={0};
  7772. DEBUG_INFO("sendUnknownConfirmation...\n");
  7773. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7774. LWS_Send(message);
  7775. return result;
  7776. }
  7777. //==========================================
  7778. // Handle server request routine Start
  7779. //==========================================
  7780. int handleCancelReservationRequest(char *uuid, char *payload)
  7781. {
  7782. mtrace();
  7783. int result = FAIL;
  7784. int gunNO = 0;
  7785. int reservationIdInt = -1;
  7786. char comfirmstr[20];
  7787. DEBUG_INFO("handleCancelReservationRequest...\n");
  7788. json_object *CancelReservation;
  7789. CancelReservation = json_tokener_parse(payload);
  7790. if(!is_error(CancelReservation))
  7791. {
  7792. // Required data
  7793. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7794. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7795. }
  7796. json_object_put(CancelReservation);
  7797. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7798. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7799. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7800. if(reservationIdInt != -1)
  7801. {
  7802. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7803. //check Transaction active
  7804. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7806. {
  7807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7808. {
  7809. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7810. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7811. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7812. {
  7813. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7814. }
  7815. else
  7816. {
  7817. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7818. }
  7819. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7820. goto end;
  7821. }
  7822. }
  7823. for (int index = 0; index < CCS_QUANTITY; index++)
  7824. {
  7825. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7826. {
  7827. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7828. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7829. if(gunType[2] == GUN_TYPE_CCS)
  7830. {
  7831. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7832. }
  7833. else
  7834. {
  7835. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7836. }
  7837. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7838. goto end;
  7839. }
  7840. }
  7841. for (int index = 0; index < GB_QUANTITY; index++)
  7842. {
  7843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7844. {
  7845. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7846. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7847. if(gunType[2] == GUN_TYPE_GBT)
  7848. {
  7849. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7850. }
  7851. else
  7852. {
  7853. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7854. }
  7855. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7856. goto end;
  7857. }
  7858. }
  7859. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7860. {
  7861. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7862. {
  7863. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7864. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7865. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7866. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7867. goto end;
  7868. }
  7869. }
  7870. for (int index = 0; index < AC_QUANTITY; index++)
  7871. {
  7872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7873. {
  7874. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7875. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7877. {
  7878. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7879. }
  7880. else
  7881. {
  7882. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7883. }
  7884. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7885. goto end;
  7886. }
  7887. }
  7888. }
  7889. //The reservationId does NOT match the reservationId
  7890. sendCancelReservationConfirmation(uuid, comfirmstr);
  7891. end:
  7892. // Fill in ocpp packet uuid
  7893. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7894. return result;
  7895. }
  7896. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7897. {
  7898. mtrace();
  7899. int result = FAIL;
  7900. int gunIndex = -1;
  7901. char typeStr[16]={0};
  7902. char comfirmstr[20];
  7903. int specificId = FALSE;
  7904. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7905. json_object *ChangeAvailability;
  7906. ChangeAvailability = json_tokener_parse(payload);
  7907. if(!is_error(ChangeAvailability))
  7908. {
  7909. // Required data
  7910. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7911. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7912. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7913. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7914. }
  7915. json_object_put(ChangeAvailability);
  7916. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7917. {
  7918. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7919. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7920. }
  7921. else if(gunIndex == 0)
  7922. {
  7923. for(int i=0; i < gunTotalNumber; i++)
  7924. {
  7925. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7926. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7927. }
  7928. }
  7929. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7931. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7932. {
  7933. specificId = TRUE;
  7934. }
  7935. if(specificId == FALSE)
  7936. goto end;
  7937. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7938. {
  7939. //----------------------gunIndex is 0 ------------------------------------------------//
  7940. if(gunIndex == 0)
  7941. {
  7942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7943. {
  7944. for(int i=0; i < gunTotalNumber; i++)
  7945. {
  7946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7947. {
  7948. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7949. {
  7950. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7951. {
  7952. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7953. goto end;
  7954. }
  7955. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7956. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7957. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7958. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7959. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7960. {
  7961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7962. goto end;
  7963. }
  7964. }
  7965. }//END FOR CHAdeMO_QUANTITY
  7966. for (int index = 0; index < CCS_QUANTITY; index++)
  7967. {
  7968. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7969. {
  7970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7971. {
  7972. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7973. goto end;
  7974. }
  7975. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7976. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7977. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7978. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7980. {
  7981. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7982. goto end;
  7983. }
  7984. }
  7985. }//END FOR CCS_QUANTITY
  7986. for (int index = 0; index < GB_QUANTITY; index++)
  7987. {
  7988. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7989. {
  7990. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7991. {
  7992. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7993. goto end;
  7994. }
  7995. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7996. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7997. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7998. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7999. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8000. {
  8001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8002. goto end;
  8003. }
  8004. }
  8005. }// END FOR GB_QUANTITY
  8006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8007. {
  8008. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8009. {
  8010. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8011. {
  8012. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8013. goto end;
  8014. }
  8015. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8016. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8017. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8018. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8019. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8020. {
  8021. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8022. goto end;
  8023. }
  8024. }
  8025. }// END FOR GENERAL_GUN_QUANTITY
  8026. for (int index = 0; index < AC_QUANTITY; index++)
  8027. {
  8028. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8029. {
  8030. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8031. {
  8032. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8033. goto end;
  8034. }
  8035. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8036. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8037. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8038. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8039. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8040. {
  8041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8042. goto end;
  8043. }
  8044. }
  8045. }//END FOR AC_QUANTITY
  8046. }// END FOR gunTotalNumber
  8047. }
  8048. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8049. {
  8050. for(int i=0; i < gunTotalNumber; i++)
  8051. {
  8052. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8053. {
  8054. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8055. goto end;
  8056. }
  8057. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8058. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8059. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8060. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8061. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8062. {
  8063. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8064. goto end;
  8065. }
  8066. }
  8067. }
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8069. goto end;
  8070. }
  8071. //----------------------gunIndex is not 0 ------------------------------------------------//
  8072. //check Transaction active
  8073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8074. {
  8075. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8076. {
  8077. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8078. {
  8079. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8080. goto end;
  8081. }
  8082. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8083. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8087. {
  8088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8089. goto end;
  8090. }
  8091. else
  8092. {
  8093. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8094. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8095. goto end;
  8096. }
  8097. }
  8098. }//END FOR CHAdeMO_QUANTITY
  8099. for (int index = 0; index < CCS_QUANTITY; index++)
  8100. {
  8101. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8102. {
  8103. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8104. {
  8105. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8106. goto end;
  8107. }
  8108. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8109. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8110. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8113. {
  8114. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8115. goto end;
  8116. }
  8117. else
  8118. {
  8119. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8120. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8121. goto end;
  8122. }
  8123. }
  8124. }//END FOR CCS_QUANTITY
  8125. for (int index = 0; index < GB_QUANTITY; index++)
  8126. {
  8127. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8128. {
  8129. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8130. {
  8131. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8132. goto end;
  8133. }
  8134. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8139. {
  8140. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8141. goto end;
  8142. }
  8143. else
  8144. {
  8145. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8146. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8147. goto end;
  8148. }
  8149. }
  8150. }// END FOR GB_QUANTITY
  8151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8152. {
  8153. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8154. {
  8155. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8156. {
  8157. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8158. goto end;
  8159. }
  8160. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8163. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8165. {
  8166. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8167. goto end;
  8168. }
  8169. else
  8170. {
  8171. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8172. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8173. goto end;
  8174. }
  8175. }
  8176. }// END FOR GENERAL_GUN_QUANTITY
  8177. for (int index = 0; index < AC_QUANTITY; index++)
  8178. {
  8179. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8180. {
  8181. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8182. {
  8183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8184. goto end;
  8185. }
  8186. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8191. {
  8192. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8193. goto end;
  8194. }
  8195. else
  8196. {
  8197. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8199. goto end;
  8200. }
  8201. }
  8202. }//END FOR AC_QUANTITY
  8203. }//END FOR AvailabilityTypeStr[Inoperative]
  8204. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8205. {
  8206. //----------------------gunIndex is 0 ------------------------------------------------//
  8207. if(gunIndex == 0)
  8208. {
  8209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8210. {
  8211. for(int i=0; i < gunTotalNumber; i++)
  8212. {
  8213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8214. {
  8215. 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
  8216. {
  8217. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8218. goto end;
  8219. }
  8220. }//END FOR CHAdeMO_QUANTITY
  8221. for (int index = 0; index < CCS_QUANTITY; index++)
  8222. {
  8223. 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
  8224. {
  8225. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8226. goto end;
  8227. }
  8228. }//END FOR CCS_QUANTITY
  8229. for (int index = 0; index < GB_QUANTITY; index++)
  8230. {
  8231. 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
  8232. {
  8233. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8235. goto end;
  8236. }
  8237. }// END FOR GB_QUANTITY
  8238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8239. {
  8240. 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
  8241. {
  8242. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8243. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8244. goto end;
  8245. }
  8246. }// END FOR GENERAL_GUN_QUANTITY
  8247. for (int index = 0; index < AC_QUANTITY; index++)
  8248. {
  8249. 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
  8250. {
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8252. goto end;
  8253. }
  8254. }//END FOR CHAdeMO_QUANTITY
  8255. }// END FOR gunTotalNumber
  8256. }
  8257. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8258. {
  8259. for(int i=0; i < gunTotalNumber; i++)
  8260. {
  8261. for (int index = 0; index < AC_QUANTITY; index++)
  8262. {
  8263. 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
  8264. {
  8265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8266. goto end;
  8267. }
  8268. }//END FOR CHAdeMO_QUANTITY
  8269. } // END FOR gunTotalNumber
  8270. }
  8271. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8272. goto end;
  8273. }
  8274. //----------------------gunIndex is not 0 ------------------------------------------------//
  8275. //check Transaction active
  8276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8277. {
  8278. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8279. {
  8280. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8281. goto end;
  8282. }
  8283. }//END FOR CHAdeMO_QUANTITY
  8284. for (int index = 0; index < CCS_QUANTITY; index++)
  8285. {
  8286. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8287. {
  8288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8289. goto end;
  8290. }
  8291. }//END FOR CCS_QUANTITY
  8292. for (int index = 0; index < GB_QUANTITY; index++)
  8293. {
  8294. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8295. {
  8296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8297. goto end;
  8298. }
  8299. }// END FOR GB_QUANTITY
  8300. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8301. {
  8302. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8305. goto end;
  8306. }
  8307. }// END FOR GENERAL_GUN_QUANTITY
  8308. for (int index = 0; index < AC_QUANTITY; index++)
  8309. {
  8310. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8311. {
  8312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8313. goto end;
  8314. }
  8315. }//END FOR AC_QUANTITY
  8316. }//END FOR AvailabilityTypeStr[Operative]
  8317. end:
  8318. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8319. {
  8320. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8321. }
  8322. else
  8323. {
  8324. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8325. }
  8326. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8327. {
  8328. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8329. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8330. }
  8331. else if(gunIndex == 0)
  8332. {
  8333. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8334. {
  8335. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8336. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8337. }
  8338. }
  8339. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8340. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8341. return result;
  8342. }
  8343. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8344. {
  8345. mtrace();
  8346. int valueInvalid = NO;
  8347. int result = FAIL;
  8348. char keystr[40]={0};
  8349. char valuestr[501]={0}; //value should be limited in 500 bytes
  8350. char comfirmstr[20]={0};
  8351. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8352. json_object *ChangeConfiguration;
  8353. ChangeConfiguration = json_tokener_parse(payload);
  8354. if(!is_error(ChangeConfiguration))
  8355. {
  8356. // Required data
  8357. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8358. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8359. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8360. {
  8361. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8362. }
  8363. else
  8364. {
  8365. valueInvalid = YES;
  8366. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8367. }
  8368. }
  8369. json_object_put(ChangeConfiguration);
  8370. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8371. {
  8372. DEBUG_ERROR("Payload is null or not accepted.\n");
  8373. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8374. }
  8375. else
  8376. {
  8377. int status = setKeyValue(keystr, valuestr);
  8378. switch(status)
  8379. {
  8380. case ConfigurationStatus_Accepted:
  8381. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8382. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8383. StoreConfigurationTable();
  8384. break;
  8385. case RebootRequired:
  8386. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8387. StoreConfigurationTable();
  8388. break;
  8389. case NotSupported:
  8390. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8391. break;
  8392. case ConfigurationStatus_Rejected:
  8393. default:
  8394. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8395. break;
  8396. }
  8397. }
  8398. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8399. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8400. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8401. {
  8402. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8403. SetOcppConnStatus(FALSE);
  8404. }
  8405. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8406. {
  8407. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8408. }
  8409. return result;
  8410. }
  8411. int handleClearCacheRequest(char *uuid, char *payload)
  8412. {
  8413. mtrace();
  8414. int result = FAIL;
  8415. char comfirmstr[20];
  8416. char rmFileCmd[100]={0};
  8417. struct stat stats;
  8418. DEBUG_INFO("handleClearCacheRequest...\n");
  8419. stat("/Storage/OCPP_PH", &stats);
  8420. // Check for directory existence
  8421. if (S_ISDIR(stats.st_mode) == 1)
  8422. {}
  8423. else
  8424. {
  8425. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8426. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8427. system(rmFileCmd);
  8428. }
  8429. if(OCPP_cleanLocalCache())
  8430. {
  8431. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8432. }
  8433. else
  8434. {
  8435. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8436. }
  8437. sendClearCacheConfirmation(uuid, comfirmstr);
  8438. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8439. return result;
  8440. }
  8441. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8442. {
  8443. mtrace();
  8444. int result = FAIL;
  8445. int resultRename;
  8446. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8447. char chargingProfilePurposeStr[26]={0};
  8448. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8449. char tempchargingProfilePurposeStr[26]={0};
  8450. char str[100]={0};
  8451. char fname[200]={0};
  8452. char comfirmstr[20]={0};
  8453. char word[1600]={0};
  8454. int clearflag = FALSE;
  8455. int chargingProfileIdIsNULL = FALSE;
  8456. int connectorIsNULL = FALSE;
  8457. int chargingProfilePurposeIsNULL = FALSE;
  8458. int stackLevelIsNULL = FALSE;
  8459. //int GotoEnd = FALSE;
  8460. FILE *fptr1, *fptr2;
  8461. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8462. int n_chargingProfile=0;
  8463. int isEmptyFile = FALSE;
  8464. char sLineWord[1600]={0};
  8465. char chargingProfiles[10][100]={0};
  8466. int ChargeProfileCount = 0;
  8467. int ch;
  8468. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8469. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8470. json_object *ClearChargingProfile;
  8471. ClearChargingProfile = json_tokener_parse(payload);
  8472. if(!is_error(ClearChargingProfile))
  8473. {
  8474. // Optional data
  8475. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8476. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8477. else
  8478. chargingProfileIdIsNULL = TRUE;
  8479. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8480. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8481. else
  8482. connectorIsNULL = TRUE;
  8483. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8484. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8485. else
  8486. chargingProfilePurposeIsNULL = TRUE;
  8487. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8488. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8489. else
  8490. stackLevelIsNULL = TRUE;
  8491. }
  8492. json_object_put(ClearChargingProfile);
  8493. if(connectorIsNULL == FALSE)
  8494. {
  8495. switch(connectorIdInt)
  8496. {
  8497. case 0:
  8498. if(chargingProfilePurposeIsNULL == TRUE)
  8499. {
  8500. int l = 0;
  8501. strcpy(fname, ChargePointMaxProfile_JSON);
  8502. if((access(fname,F_OK))!=-1)
  8503. {
  8504. strcpy(chargingProfiles[l], fname);
  8505. l = l + 1;
  8506. }
  8507. strcpy(fname, TxDefaultProfile_0_JSON);
  8508. if((access(fname,F_OK))!=-1)
  8509. {
  8510. strcpy(chargingProfiles[l], fname);
  8511. l = l + 1;
  8512. }
  8513. ChargeProfileCount = l;
  8514. }
  8515. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8516. {
  8517. strcpy(fname, ChargePointMaxProfile_JSON);
  8518. if((access(fname,F_OK))!=-1)
  8519. {
  8520. strcpy(chargingProfiles[0], fname);
  8521. ChargeProfileCount = 1;
  8522. }
  8523. }
  8524. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8525. {
  8526. strcpy(fname, TxDefaultProfile_0_JSON);
  8527. if((access(fname,F_OK))!=-1)
  8528. {
  8529. strcpy(chargingProfiles[0], fname);
  8530. ChargeProfileCount = 1;
  8531. }
  8532. }
  8533. break;
  8534. default:
  8535. if(chargingProfilePurposeIsNULL == TRUE)
  8536. {
  8537. int m = 0;
  8538. memset(fname, 0, ARRAY_SIZE(fname));
  8539. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8540. if((access(fname,F_OK))!=-1)
  8541. {
  8542. strcpy(chargingProfiles[m], fname);
  8543. m = m + 1;
  8544. }
  8545. memset(fname, 0, ARRAY_SIZE(fname));
  8546. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8547. if((access(fname,F_OK))!=-1)
  8548. {
  8549. strcpy(chargingProfiles[m], fname);
  8550. m = m + 1;
  8551. }
  8552. ChargeProfileCount = m;
  8553. }
  8554. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8555. {
  8556. //strcpy(fname, TxDefaultProfile_1_JSON);
  8557. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8558. if((access(fname,F_OK))!=-1)
  8559. {
  8560. strcpy(chargingProfiles[0], fname);
  8561. ChargeProfileCount = 1;
  8562. }
  8563. }
  8564. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8565. {
  8566. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8567. if((access(fname,F_OK))!=-1)
  8568. {
  8569. strcpy(chargingProfiles[0], fname);
  8570. ChargeProfileCount = 1;
  8571. }
  8572. //strcpy(fname, TxProfile_1_JSON);
  8573. }
  8574. //strcpy(fname, ChargePointMaxProfile_JSON );
  8575. break;
  8576. }
  8577. }
  8578. else // Check all Charging Profiles
  8579. {
  8580. int i = 0;
  8581. char fnametemp[200]={0};
  8582. ChargeProfileCount = 0;
  8583. //Check ChargePointMaxProfile.json exit
  8584. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8585. {
  8586. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8587. i = i + 1;
  8588. }
  8589. //Check TxDefaultProfile_0.json exit
  8590. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8591. {
  8592. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8593. i = i + 1;
  8594. }
  8595. //Check TxDefaultProfile_%d.json
  8596. for(int j=1; j <= gunTotalNumber; j++)
  8597. {
  8598. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8599. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8600. if((access(fnametemp,F_OK))!=-1)
  8601. {
  8602. strcpy(chargingProfiles[i], fnametemp);
  8603. i = i + 1;
  8604. }
  8605. }
  8606. //Check TxProfile_%d.json
  8607. for(int j=1; j <= gunTotalNumber; j++)
  8608. {
  8609. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8610. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8611. if((access(fnametemp,F_OK))!=-1)
  8612. {
  8613. strcpy(chargingProfiles[i], fnametemp);
  8614. i = i + 1;
  8615. }
  8616. }
  8617. ChargeProfileCount = i;
  8618. }// End connectorIsNULL is TRUE
  8619. if(ChargeProfileCount == 0)
  8620. {
  8621. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8622. goto end;
  8623. }
  8624. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8627. goto end;
  8628. }
  8629. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8630. {
  8631. memset(str, 0, ARRAY_SIZE(str));
  8632. // clear temp file
  8633. sprintf(str,"rm -f %s",temp);
  8634. system(str);
  8635. for(int k=0; k < ChargeProfileCount; k++)
  8636. {
  8637. memset(str, 0, ARRAY_SIZE(str));
  8638. //clear file in C
  8639. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8640. system(str);
  8641. }
  8642. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8643. goto end;
  8644. }
  8645. else if(connectorIsNULL == TRUE)
  8646. {
  8647. for(int k=0; k < ChargeProfileCount; k++)
  8648. {
  8649. fptr1 = fopen(chargingProfiles[k], "r");
  8650. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8651. //Check Charging Profile Count
  8652. while(fscanf(fptr1, "%s", word) != EOF)
  8653. {
  8654. //DEBUG_INFO("word=%s\n",word);
  8655. if(strstr(word, "chargingProfileId")!= NULL)
  8656. {
  8657. //DEBUG_INFO("test chargingProfileId \n");
  8658. n_chargingProfile = n_chargingProfile + 1;
  8659. //DEBUG_INFO("chargingProfileId Found\n");
  8660. }
  8661. }
  8662. rewind(fptr1);
  8663. //search Charging Profile Element
  8664. //int i= 0;
  8665. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8666. {
  8667. json_object *tmpProfilee;
  8668. tmpProfilee = json_tokener_parse(sLineWord);
  8669. if(!is_error(tmpProfilee))
  8670. {
  8671. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8672. {
  8673. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8674. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8675. }
  8676. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8677. {
  8678. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8679. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8680. }
  8681. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8682. {
  8683. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8684. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8685. }
  8686. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8687. {
  8688. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8689. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8690. }
  8691. }
  8692. json_object_put(tmpProfilee);
  8693. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8694. {
  8695. //------- not write to fptr2-------//
  8696. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8697. //clearflag = TRUE;
  8698. }
  8699. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8700. {
  8701. //------- not write to fptr2-------//
  8702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8703. }
  8704. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8705. {
  8706. //------- not write to fptr2-------//
  8707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8708. }
  8709. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8710. {
  8711. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8712. }
  8713. else
  8714. {
  8715. fprintf(fptr2, sLineWord);//writing data into file
  8716. }
  8717. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8718. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8719. if(clearflag == TRUE)
  8720. {
  8721. fclose(fptr1);
  8722. fclose(fptr2);
  8723. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8724. system(str);
  8725. // clear temp file
  8726. sprintf(str,"rm -f %s",temp);
  8727. system(str);
  8728. }
  8729. else
  8730. {
  8731. fclose(fptr1);
  8732. fclose(fptr2);
  8733. memset(str, 0, ARRAY_SIZE(str));
  8734. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8735. system(str);
  8736. resultRename = rename(temp, chargingProfiles[k]);
  8737. if(resultRename == 0)
  8738. {
  8739. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8740. }
  8741. else
  8742. {
  8743. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8744. }
  8745. if(comfirmstr[0]== 0)
  8746. {
  8747. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8748. }
  8749. //Check chargingProfile is empty file
  8750. /*------ Read the file ----------------*/
  8751. fptr1=fopen(chargingProfiles[k],"r");
  8752. ch=fgetc(fptr1);
  8753. rewind(fptr1);
  8754. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8755. if(ch!=EOF)
  8756. {
  8757. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8758. {
  8759. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8760. if(sLineWord[0]=='\0')
  8761. {
  8762. isEmptyFile = TRUE;
  8763. break;
  8764. }
  8765. else
  8766. {
  8767. isEmptyFile = FALSE;
  8768. break;
  8769. }
  8770. }
  8771. }
  8772. else
  8773. isEmptyFile = TRUE;
  8774. fclose(fptr1);
  8775. if(isEmptyFile == TRUE)
  8776. {
  8777. memset(str, 0, ARRAY_SIZE(str));
  8778. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8779. system(str);
  8780. }
  8781. }
  8782. }// End of while(int k=0; k < ChargePointCount; k++)
  8783. }
  8784. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8785. {
  8786. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8787. for(int k=0; k < ChargeProfileCount; k++)
  8788. {
  8789. fptr1 = fopen(chargingProfiles[k], "r");
  8790. fptr2 = fopen(temp, "w+");
  8791. //Check Charging Profile Count
  8792. while(fscanf(fptr1, "%s", word) != EOF)
  8793. {
  8794. //DEBUG_INFO("word=%s\n",word);
  8795. if(strstr(word, "chargingProfileId")!= NULL)
  8796. {
  8797. n_chargingProfile = n_chargingProfile + 1;
  8798. }
  8799. }
  8800. rewind(fptr1);
  8801. //search Charging Profile Element
  8802. //int i= 0;
  8803. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8804. {
  8805. json_object *tmpProfilee;
  8806. tmpProfilee = json_tokener_parse(sLineWord);
  8807. if(!is_error(tmpProfilee))
  8808. {
  8809. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8810. {
  8811. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8812. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8813. }
  8814. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8815. {
  8816. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8817. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8818. }
  8819. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8820. {
  8821. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8822. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8825. {
  8826. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8827. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8828. }
  8829. }
  8830. json_object_put(tmpProfilee);
  8831. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8832. {
  8833. //------- not write to fptr2-------//
  8834. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8835. //clearflag = TRUE;
  8836. }
  8837. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8838. {
  8839. //------- not write to fptr2-------//
  8840. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8841. }
  8842. else if(stackLevelIsNULL == TRUE)
  8843. {
  8844. //Clear Whole File
  8845. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8846. clearflag = TRUE;
  8847. break;
  8848. }
  8849. else
  8850. {
  8851. fprintf(fptr2, sLineWord);//writing data into file
  8852. }
  8853. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8854. }
  8855. if(clearflag == TRUE)
  8856. {
  8857. fclose(fptr1);
  8858. fclose(fptr2);
  8859. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8860. system(str);
  8861. // clear temp file
  8862. sprintf(str,"rm -f %s",temp);
  8863. system(str);
  8864. }
  8865. else
  8866. {
  8867. fclose(fptr1);
  8868. fclose(fptr2);
  8869. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8870. system(str);
  8871. resultRename = rename(temp, chargingProfiles[k]);
  8872. if(resultRename == 0)
  8873. {
  8874. DEBUG_INFO("File ChargingProfile renamed successfully");
  8875. }
  8876. else
  8877. {
  8878. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8879. }
  8880. if(comfirmstr[0]== 0)
  8881. {
  8882. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8883. }
  8884. //Check chargingProfile is empty file
  8885. /*------ Read the file ----------------*/
  8886. fptr1=fopen(chargingProfiles[k],"r");
  8887. ch=fgetc(fptr1);
  8888. rewind(fptr1);
  8889. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8890. if(ch!=EOF)
  8891. {
  8892. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8893. {
  8894. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8895. if(sLineWord[0]=='\0')
  8896. {
  8897. isEmptyFile = TRUE;
  8898. break;
  8899. }
  8900. else
  8901. {
  8902. isEmptyFile = FALSE;
  8903. break;
  8904. }
  8905. }
  8906. }
  8907. else
  8908. isEmptyFile = TRUE;
  8909. fclose(fptr1);
  8910. if(isEmptyFile == TRUE)
  8911. {
  8912. memset(str, 0, ARRAY_SIZE(str));
  8913. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8914. system(str);
  8915. }
  8916. /*------- End of reading ---------------*/
  8917. }
  8918. } // while(int k=0; k < ChargeProfileCount; k++)
  8919. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8920. end:
  8921. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8922. {
  8923. if(connectorIdInt == 0)
  8924. {
  8925. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8926. {
  8927. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8928. }
  8929. }
  8930. else
  8931. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8932. }
  8933. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8934. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8935. return result;
  8936. }
  8937. void createFirmwareVersionByDataTransfer(void)
  8938. {
  8939. json_object *FirmwareDataTransfer = json_object_new_object();
  8940. // AC & DC model
  8941. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8942. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8943. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8944. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8945. // DC model
  8946. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8947. {
  8948. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8949. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8950. (gunType[3] != GUN_TYPE_UNKNOWN))
  8951. {
  8952. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8953. }
  8954. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8955. {
  8956. // DS DM DW
  8957. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8958. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8959. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8963. }
  8964. else
  8965. {
  8966. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8968. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8969. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8970. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8979. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8980. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8981. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8982. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8983. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8984. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8985. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8986. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8987. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8988. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8989. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8990. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8991. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8992. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8993. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8994. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8995. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8996. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8997. }
  8998. }
  8999. // 4G model
  9000. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9001. {
  9002. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9003. }
  9004. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9005. json_object_put(FirmwareDataTransfer);
  9006. }
  9007. int handleDataTransferRequest(char *uuid, char *payload)
  9008. {
  9009. mtrace();
  9010. json_object *response = json_object_new_object();
  9011. int result = FAIL;
  9012. char tempvendorId[255]={0};
  9013. char tempmessageId[50]={0};
  9014. char tempdata[1024]={0};
  9015. char message[2048]={0};
  9016. DEBUG_INFO("handleDataTransferRequest...\n");
  9017. if((uuid != NULL) && (payload != NULL))
  9018. {
  9019. json_object *DataTransfer;
  9020. DataTransfer = json_tokener_parse(payload);
  9021. if(!is_error(DataTransfer))
  9022. {
  9023. // Required data
  9024. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9025. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9026. // Optional data
  9027. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9028. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9029. if(json_object_object_get(DataTransfer, "data") != NULL)
  9030. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9031. result = PASS;
  9032. }
  9033. json_object_put(DataTransfer);
  9034. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9035. {
  9036. // Send all moudle firmware version on EVSE
  9037. createFirmwareVersionByDataTransfer();
  9038. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9039. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9040. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9041. json_object_put(response);
  9042. }
  9043. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9044. {
  9045. system("/usr/bin/run_tmate_restart.sh &");
  9046. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9047. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9048. json_object_put(response);
  9049. }
  9050. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9051. {
  9052. json_object *data;
  9053. data = json_tokener_parse(tempdata);
  9054. if(!is_error(data))
  9055. {
  9056. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9057. {
  9058. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9059. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9060. if(json_object_object_get(data, "SOC") != NULL)
  9061. {
  9062. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9063. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9064. }
  9065. if(json_object_object_get(data, "Energy") != NULL)
  9066. {
  9067. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9068. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9069. }
  9070. if(json_object_object_get(data, "Duration") != NULL)
  9071. {
  9072. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9073. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9074. }
  9075. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9076. }
  9077. else
  9078. {
  9079. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9080. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9081. }
  9082. }
  9083. else
  9084. {
  9085. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9086. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9087. }
  9088. json_object_put(data);
  9089. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9090. json_object_put(response);
  9091. }
  9092. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9093. {
  9094. json_object *data;
  9095. data = json_tokener_parse(tempdata);
  9096. if(!is_error(data))
  9097. {
  9098. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9099. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9100. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9101. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9102. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9108. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9109. }
  9110. else
  9111. {
  9112. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9113. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9114. }
  9115. json_object_put(data);
  9116. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9117. json_object_put(response);
  9118. }
  9119. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9120. {
  9121. json_object *data;
  9122. data = json_tokener_parse(tempdata);
  9123. if(!is_error(data))
  9124. {
  9125. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9126. if(json_object_object_get(data, "idToken") != NULL)
  9127. {
  9128. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9129. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9130. }
  9131. if(json_object_object_get(data, "price") != NULL)
  9132. {
  9133. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9134. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9135. }
  9136. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9137. }
  9138. else
  9139. {
  9140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9141. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9142. }
  9143. json_object_put(data);
  9144. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9145. json_object_put(response);
  9146. }
  9147. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9148. {
  9149. json_object *data;
  9150. data = json_tokener_parse(tempdata);
  9151. if(!is_error(data))
  9152. {
  9153. if(json_object_object_get(data, "txId") != NULL)
  9154. {
  9155. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9156. for(int idx = 0;idx<gunTotalNumber;idx++)
  9157. {
  9158. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9159. {
  9160. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9161. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9162. if(json_object_object_get(data, "description") != NULL)
  9163. {
  9164. // California pricing V1.0
  9165. DEBUG_INFO("California pricing V1.0\n");
  9166. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9167. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9168. }
  9169. else
  9170. {
  9171. // California pricing V1.1
  9172. DEBUG_INFO("California pricing V1.1\n");
  9173. if(json_object_object_get(data, "timestamp") != NULL)
  9174. {
  9175. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9176. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9177. }
  9178. if(json_object_object_get(data, "meterValue") != NULL)
  9179. {
  9180. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9181. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9182. }
  9183. if(json_object_object_get(data, "cost") != NULL)
  9184. {
  9185. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9186. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9187. }
  9188. if(json_object_object_get(data, "state") != NULL)
  9189. {
  9190. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9191. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9192. }
  9193. if(json_object_object_get(data, "chargingPrice") != NULL)
  9194. {
  9195. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9196. {
  9197. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9198. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9199. }
  9200. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9201. {
  9202. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9203. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9204. }
  9205. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9206. {
  9207. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9208. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9209. }
  9210. }
  9211. if(json_object_object_get(data, "idlePrice") != NULL)
  9212. {
  9213. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9214. {
  9215. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9216. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9217. }
  9218. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9219. {
  9220. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9221. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9222. }
  9223. }
  9224. if(json_object_object_get(data, "nextPeriod") != NULL)
  9225. {
  9226. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9227. {
  9228. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9229. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9230. }
  9231. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9232. {
  9233. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9234. {
  9235. 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")));
  9236. 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"));
  9237. }
  9238. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9239. {
  9240. 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")));
  9241. 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"));
  9242. }
  9243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9244. {
  9245. 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")));
  9246. 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"));
  9247. }
  9248. }
  9249. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9250. {
  9251. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9252. {
  9253. 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")));
  9254. 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"));
  9255. }
  9256. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9257. {
  9258. 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")));
  9259. 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"));
  9260. }
  9261. }
  9262. }
  9263. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9264. {
  9265. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9266. {
  9267. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9268. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9269. }
  9270. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9271. {
  9272. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9273. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9274. }
  9275. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9276. {
  9277. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9278. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9279. }
  9280. }
  9281. }
  9282. }
  9283. }
  9284. }
  9285. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9286. }
  9287. else
  9288. {
  9289. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9290. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9291. }
  9292. json_object_put(data);
  9293. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9294. json_object_put(response);
  9295. }
  9296. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9297. {
  9298. json_object *data;
  9299. data = json_tokener_parse(tempdata);
  9300. if(!is_error(data))
  9301. {
  9302. if(json_object_object_get(data, "txId") != NULL)
  9303. {
  9304. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9305. for(int idx = 0;idx<gunTotalNumber;idx++)
  9306. {
  9307. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9308. {
  9309. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9310. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9311. if(json_object_object_get(data, "description") != NULL)
  9312. {
  9313. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9314. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9315. }
  9316. }
  9317. }
  9318. }
  9319. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9320. }
  9321. else
  9322. {
  9323. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9324. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9325. }
  9326. json_object_put(data);
  9327. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9328. json_object_put(response);
  9329. }
  9330. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9331. {
  9332. json_object *data;
  9333. data = json_tokener_parse(tempdata);
  9334. if(!is_error(data))
  9335. {
  9336. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9337. if(json_object_object_get(data, "Content_Type") != NULL)
  9338. {
  9339. 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))
  9340. {
  9341. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9342. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9343. {
  9344. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9345. }
  9346. }
  9347. else
  9348. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9349. }
  9350. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9351. }
  9352. else
  9353. {
  9354. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9355. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9356. }
  9357. json_object_put(data);
  9358. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9359. json_object_put(response);
  9360. }
  9361. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9362. {
  9363. json_object *data;
  9364. data = json_tokener_parse(tempdata);
  9365. if(!is_error(data))
  9366. {
  9367. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9368. if(json_object_object_get(data, "ConnectorId") != NULL)
  9369. {
  9370. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9371. }
  9372. if(json_object_object_get(data, "SerialNo") != NULL)
  9373. {
  9374. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9375. }
  9376. if(json_object_object_get(data, "Page_Index") != NULL)
  9377. {
  9378. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9379. }
  9380. if(json_object_object_get(data, "Duration") != NULL)
  9381. {
  9382. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9383. }
  9384. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9385. }
  9386. else
  9387. {
  9388. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9389. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9390. }
  9391. json_object_put(data);
  9392. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9393. json_object_put(response);
  9394. }
  9395. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9396. {
  9397. json_object *data;
  9398. data = json_tokener_parse(tempdata);
  9399. if(!is_error(data))
  9400. {
  9401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9402. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9403. {
  9404. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9405. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9406. else
  9407. {
  9408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9409. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9410. }
  9411. }
  9412. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9413. {
  9414. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9415. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9416. else
  9417. {
  9418. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9419. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9420. }
  9421. }
  9422. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9423. {
  9424. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9425. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9426. else
  9427. {
  9428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9429. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9430. }
  9431. }
  9432. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9433. {
  9434. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9435. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9436. else
  9437. {
  9438. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9439. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9440. }
  9441. }
  9442. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9443. {
  9444. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9445. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9446. else
  9447. {
  9448. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9449. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9450. }
  9451. }
  9452. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9453. {
  9454. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9455. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9456. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9457. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9458. else
  9459. {
  9460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9462. }
  9463. }
  9464. if(json_object_object_get(data, "isAuthentication") != NULL)
  9465. {
  9466. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9467. {
  9468. case 0:
  9469. case 1:
  9470. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9471. break;
  9472. default:
  9473. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9474. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9475. break;
  9476. }
  9477. }
  9478. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9479. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9480. }
  9481. else
  9482. {
  9483. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9484. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9485. }
  9486. json_object_put(data);
  9487. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9488. json_object_put(response);
  9489. }
  9490. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9491. {
  9492. json_object *data;
  9493. data = json_tokener_parse(tempdata);
  9494. if(!is_error(data))
  9495. {
  9496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9497. if(json_object_object_get(data, "stationName") != NULL)
  9498. {
  9499. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9500. }
  9501. else
  9502. {
  9503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9504. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9505. }
  9506. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9507. {
  9508. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9509. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9510. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9511. }
  9512. }
  9513. else
  9514. {
  9515. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9516. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9517. }
  9518. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9519. json_object_put(response);
  9520. }
  9521. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9522. {
  9523. json_object *data;
  9524. data = json_tokener_parse(tempdata);
  9525. if(!is_error(data))
  9526. {
  9527. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9528. if(json_object_object_get(data, "weatherId") != NULL)
  9529. {
  9530. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9531. }
  9532. else
  9533. {
  9534. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9535. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9536. }
  9537. if(json_object_object_get(data, "Temperature") != NULL)
  9538. {
  9539. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9540. }
  9541. else
  9542. {
  9543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9544. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9545. }
  9546. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9547. {
  9548. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9549. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9550. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9551. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9552. }
  9553. }
  9554. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9555. {
  9556. json_object *data;
  9557. data = json_tokener_parse(tempdata);
  9558. if(!is_error(data))
  9559. {
  9560. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9561. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9562. {
  9563. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9564. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9565. }
  9566. else
  9567. {
  9568. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9569. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9570. }
  9571. }
  9572. else
  9573. {
  9574. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9575. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9576. }
  9577. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9578. json_object_put(response);
  9579. }
  9580. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9581. {
  9582. json_object *data;
  9583. data = json_tokener_parse(tempdata);
  9584. if(!is_error(data))
  9585. {
  9586. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9587. {
  9588. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9589. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9590. if(gun_index < gunTotalNumber)
  9591. {
  9592. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9593. {
  9594. json_object *responsedata = json_object_new_object();
  9595. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9596. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9597. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9598. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9599. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9600. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9601. }
  9602. else
  9603. {
  9604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9605. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9606. }
  9607. }
  9608. else
  9609. {
  9610. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9611. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9612. }
  9613. }
  9614. else
  9615. {
  9616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9617. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9618. }
  9619. }
  9620. else
  9621. {
  9622. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9623. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9624. }
  9625. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9626. json_object_put(response);
  9627. }
  9628. else
  9629. {
  9630. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9631. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9632. }
  9633. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9634. json_object_put(response);
  9635. }
  9636. else
  9637. {
  9638. // Can not find valid message id
  9639. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9640. }
  9641. }
  9642. else
  9643. {
  9644. // Payload is null
  9645. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9646. }
  9647. LWS_Send(message);
  9648. return result;
  9649. }
  9650. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9651. {
  9652. mtrace();
  9653. int result = FAIL;
  9654. int connectorIdInt, durationInt;
  9655. char chargingRateUnitStr[4]={0};
  9656. char comfirmstr[20];
  9657. int confirmPeriods = 0;
  9658. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9659. json_object *GetCompositeSchedule;
  9660. GetCompositeSchedule = json_tokener_parse(payload);
  9661. if(!is_error(GetCompositeSchedule))
  9662. {
  9663. // Required data
  9664. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9665. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9666. else
  9667. connectorIdInt = -1;
  9668. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9669. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9670. else
  9671. durationInt = 86400;
  9672. // Optional data
  9673. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9674. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9675. }
  9676. json_object_put(GetCompositeSchedule);
  9677. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9678. if((connectorIdInt == 0) ||
  9679. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9680. {
  9681. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9682. struct StructChargingProfile tmpProfile[1];
  9683. if(strstr(chargingRateUnitStr, "W") != NULL)
  9684. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9685. else
  9686. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9687. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9688. {
  9689. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9690. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9691. }
  9692. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9693. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9694. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9695. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9696. {
  9697. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9698. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9699. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9700. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9701. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9702. {
  9703. confirmPeriods = idx;
  9704. break;
  9705. }
  9706. }
  9707. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9708. {
  9709. confirmPeriods += 1;
  9710. }
  9711. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9712. }
  9713. else
  9714. {
  9715. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9716. }
  9717. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9718. return result;
  9719. }
  9720. int handleGetConfigurationRequest(char *uuid, char *payload)
  9721. {
  9722. mtrace();
  9723. int result = FAIL;
  9724. int MaxKeySupported = 0;
  9725. int n_keys = 0;
  9726. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9727. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9728. json_object *GetConfiguration;
  9729. GetConfiguration = json_tokener_parse(payload);
  9730. if(!is_error(GetConfiguration))
  9731. {
  9732. // Optional data
  9733. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9734. {
  9735. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9736. {
  9737. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9738. n_keys = idx + 1;
  9739. }
  9740. }
  9741. }
  9742. json_object_put(GetConfiguration);
  9743. UnknownKeynum = 0;
  9744. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9745. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9746. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9747. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9748. if(n_keys != 0)
  9749. {
  9750. for(int i=0;i<n_keys;i++)
  9751. {
  9752. getKeyValue(requestKey[i]);
  9753. }
  9754. }
  9755. else
  9756. {
  9757. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9758. getKeyValue("");
  9759. }
  9760. processUnkownKey();
  9761. sendGetConfigurationConfirmation(uuid);
  9762. return result;
  9763. }
  9764. static char fnamePlusPath[100]={0};
  9765. static char fnamePWithNoPath[60]={0};
  9766. void checkUploadLog(void)
  9767. {
  9768. FILE *fp;
  9769. /* Open the command for reading. */
  9770. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9771. if (fp == NULL) {
  9772. DEBUG_WARN("Failed to run command\n" );
  9773. exit(1);
  9774. }
  9775. int ftppathlen = 0;
  9776. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9777. int i = 0;
  9778. /* Read the output a line at a time - output it. */
  9779. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9780. if(i==0)
  9781. {
  9782. ftppathlen = strlen(fnamePlusPath);
  9783. DEBUG_INFO("%s\n", fnamePlusPath);
  9784. fnamePlusPath[ftppathlen]='\0';
  9785. break;
  9786. }
  9787. i= i+1;
  9788. }
  9789. /* close */
  9790. pclose(fp);
  9791. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9792. {
  9793. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9794. {
  9795. fnamePlusPath[k]='\0';
  9796. }
  9797. }
  9798. i=1;
  9799. //char fname[60]={0};
  9800. while(i < ftppathlen)
  9801. {
  9802. int len=ftppathlen-i;
  9803. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9804. {
  9805. DEBUG_INFO("compare '/' all right\n");
  9806. break;
  9807. }
  9808. i=i+1;
  9809. }
  9810. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9811. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9812. fnamePWithNoPath[i+1] = '\0';
  9813. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9814. {
  9815. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9816. {
  9817. fnamePWithNoPath[j]='\0';
  9818. }
  9819. }
  9820. FILE* fp1 = fopen(fnamePlusPath, "r");
  9821. if (fp1)
  9822. {
  9823. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9824. // file exists
  9825. fclose(fp1);
  9826. }
  9827. else
  9828. {
  9829. // file doesn't exist
  9830. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9831. }
  9832. }
  9833. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9834. {
  9835. mtrace();
  9836. int result = FAIL;
  9837. time_t CurrentTime;
  9838. struct tm *tm;
  9839. pthread_t th_Status;
  9840. CurrentTime = time(NULL);
  9841. tm = localtime(&CurrentTime);
  9842. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9843. 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);
  9844. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9845. if(!interLock.isGetDiagnosticGoing)
  9846. {
  9847. interLock.isGetDiagnosticGoing = 1;
  9848. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9849. sleep(1);
  9850. }
  9851. else
  9852. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9853. return result;
  9854. }
  9855. void* GetDiagnosticsProcess(void* data)
  9856. {
  9857. pthread_detach(pthread_self());
  9858. mtrace();
  9859. int retriesInt=0, retryIntervalInt=0;
  9860. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9861. 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};
  9862. int port=0;
  9863. int isSuccess = FALSE;
  9864. char ftpbuf[200]={0};
  9865. char cmdBuf[2048];
  9866. struct tm *tmNow;
  9867. time_t CurrentTime;
  9868. struct tm tmStart;
  9869. struct tm tmStop;
  9870. CurrentTime = time(NULL);
  9871. tmNow=localtime(&CurrentTime);
  9872. uint16_t targetYear, targetMonth;
  9873. json_object *GetDiagnostics;
  9874. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9875. GetDiagnostics = json_tokener_parse(data);
  9876. if(!is_error(GetDiagnostics))
  9877. {
  9878. // Required data
  9879. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9880. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9881. // Optional data
  9882. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9883. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9884. else
  9885. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9886. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9887. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9888. else
  9889. retryIntervalInt = 30;
  9890. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9891. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9892. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9893. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9894. }
  9895. json_object_put(GetDiagnostics);
  9896. // Pack log to compress file
  9897. 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) &&
  9898. (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))
  9899. {
  9900. // Pack system log
  9901. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9902. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9903. targetYear = tmStart.tm_year;
  9904. targetMonth = tmStart.tm_mon;
  9905. do
  9906. {
  9907. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9908. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9909. if(targetMonth+1>=13)
  9910. {
  9911. targetYear += 1;
  9912. targetMonth = 1;
  9913. }
  9914. else
  9915. {
  9916. targetMonth += 1;
  9917. }
  9918. }while((targetYear < (tmNow->tm_year+1900)) ||
  9919. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9920. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9921. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9922. system(cmdBuf);
  9923. // Pack charging & event log
  9924. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9925. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9926. targetYear = tmStart.tm_year;
  9927. targetMonth = tmStart.tm_mon;
  9928. do
  9929. {
  9930. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9931. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9932. if(targetMonth+1>=13)
  9933. {
  9934. targetYear += 1;
  9935. targetMonth = 1;
  9936. }
  9937. else
  9938. {
  9939. targetMonth += 1;
  9940. }
  9941. }while((targetYear < (tmNow->tm_year+1900)) ||
  9942. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9943. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9944. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9945. system(cmdBuf);
  9946. // Combine log file
  9947. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9948. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9949. }
  9950. else
  9951. {
  9952. system("exec /root/logPackTools 'log' 6");
  9953. }
  9954. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9955. system(cmdBuf);
  9956. checkUploadLog();
  9957. //****************location*******************/
  9958. if(strcmp(locationstr,"")==0)
  9959. {
  9960. DEBUG_INFO("location is <Empty>!\n");
  9961. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9962. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9963. goto end;
  9964. }
  9965. memset(protocol, 0, ARRAY_SIZE(protocol));
  9966. memset(user, 0, ARRAY_SIZE(user) );
  9967. memset(password, 0, ARRAY_SIZE(password));
  9968. memset(host, 0, ARRAY_SIZE(host));
  9969. memset(path, 0, ARRAY_SIZE(path));
  9970. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9971. memset(host1, 0, ARRAY_SIZE(host1));
  9972. memset(path1, 0, ARRAY_SIZE(path1));
  9973. /*location: ftp://user:password@host:port/path*/
  9974. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9975. if((access(fnamePlusPath,F_OK))!=-1)
  9976. {
  9977. DEBUG_INFO("fnamePlusPath exist.\n");
  9978. }
  9979. else
  9980. {
  9981. DEBUG_INFO("fnamePlusPath not exist!\n");
  9982. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9983. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9984. goto end;
  9985. }
  9986. if(strchr(locationstr,'@')==NULL)
  9987. {
  9988. sscanf(locationstr,
  9989. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9990. protocol, host, &port, path);
  9991. strcpy(user,"anonymous");
  9992. strcpy(password,"");
  9993. }
  9994. else
  9995. {
  9996. //DEBUG_INFO("pch=%s\n", pch);
  9997. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9998. protocol, user, password, host, &port, path);
  9999. }
  10000. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10001. {
  10002. DEBUG_INFO("protocol is not ftp/http ! \n");
  10003. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10004. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10005. goto end;
  10006. }
  10007. if(strncmp(locationstr,"http", 4) == 0)
  10008. {
  10009. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10010. sprintf(ftppath,"/%s", path);
  10011. do
  10012. {
  10013. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10014. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10015. sleep(3);
  10016. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10017. if(!isSuccess)
  10018. {
  10019. DEBUG_INFO("Diagnostics fail.\n");
  10020. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10021. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10022. sleep(retryIntervalInt);
  10023. }
  10024. else
  10025. {
  10026. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10027. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10028. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10029. }
  10030. retriesInt--;
  10031. }while((isSuccess == 0)&&(retriesInt >= 0));
  10032. }
  10033. else
  10034. {
  10035. sscanf(host,"%[^/]%s",host1, path1);
  10036. if(strlen(path) > 0)
  10037. sprintf(ftppath,"/%s", path);
  10038. else
  10039. sprintf(ftppath,"/%s", path1);
  10040. int ftppathlen=strlen(ftppath);
  10041. int i=1;
  10042. char filenametemp[50];
  10043. while(i < ftppathlen)
  10044. {
  10045. int len=ftppathlen-i;
  10046. if(ftppath[len]== 47) // '/' ascll code: 47
  10047. {
  10048. DEBUG_INFO("find '/' all right\n");
  10049. break;
  10050. }
  10051. i=i+1;
  10052. }
  10053. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10054. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10055. filenametemp[i+1] = 0;
  10056. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10057. if(port == 0)
  10058. port = 21;
  10059. do
  10060. {
  10061. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10062. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10063. sleep(3);
  10064. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10065. if(!isSuccess)
  10066. {
  10067. DEBUG_INFO("Diagnostics fail.\n");
  10068. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10069. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10070. sleep(retryIntervalInt);
  10071. }
  10072. else
  10073. {
  10074. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10075. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10076. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10077. }
  10078. retriesInt--;
  10079. }while((!isSuccess)&&(retriesInt >= 0));
  10080. }
  10081. end:
  10082. system("rm -f /mnt/*");
  10083. sleep(5);
  10084. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10085. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10086. interLock.isGetDiagnosticGoing = 0;
  10087. pthread_exit(NULL);
  10088. }
  10089. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10090. {
  10091. mtrace();
  10092. int result = FAIL;
  10093. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10094. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10095. {
  10096. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10097. locallistVersion = -1;
  10098. }
  10099. else
  10100. {
  10101. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10102. locallistVersion = 0;
  10103. OCPP_getListVerion();
  10104. }
  10105. //from db.OCPP_getListVerion
  10106. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10107. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10108. sendGetLocalListVersionConfirmation(uuid,"");
  10109. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10110. return result;
  10111. }
  10112. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10113. {
  10114. mtrace();
  10115. int result = FAIL;
  10116. int connectorIdInt=-1;
  10117. int tempIndex = 0;
  10118. int connectorIdIsNULL, chargingProfileIsNULL;
  10119. char comfirmstr[20]={0};
  10120. char cmdBuf[512];
  10121. json_object *RemoteStartTransaction;
  10122. FILE *fp;
  10123. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10124. if(server_pending == TRUE)
  10125. {
  10126. return 0;
  10127. }
  10128. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10129. RemoteStartTransaction = json_tokener_parse(payload);
  10130. if(!is_error(RemoteStartTransaction))
  10131. {
  10132. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10133. {
  10134. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10135. }
  10136. else
  10137. {
  10138. connectorIdIsNULL = TRUE;
  10139. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10140. {
  10141. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10142. {
  10143. connectorIdIsNULL = FALSE;
  10144. connectorIdInt = (gun_index+1);
  10145. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10146. break;
  10147. }
  10148. }
  10149. }
  10150. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10151. {
  10152. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10153. // Required data
  10154. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10155. // Optional data
  10156. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10157. {
  10158. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10159. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10160. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10161. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10162. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10163. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10164. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10165. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10166. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10167. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10168. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10169. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10170. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10171. {
  10172. 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")));
  10173. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10174. 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"));
  10175. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10176. 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"));
  10177. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10178. 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")));
  10179. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10180. {
  10181. 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++)
  10182. {
  10183. 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"));
  10184. 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"));
  10185. 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)
  10186. 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"));
  10187. }
  10188. }
  10189. }
  10190. }
  10191. else
  10192. {
  10193. chargingProfileIsNULL = TRUE;
  10194. }
  10195. }
  10196. }
  10197. else
  10198. {
  10199. connectorIdIsNULL = TRUE;
  10200. }
  10201. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10202. {
  10203. DEBUG_WARN("Connector id is NULL\n.");
  10204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10205. goto end;
  10206. }
  10207. /*
  10208. enum _SYSTEM_STATUS
  10209. {
  10210. S_BOOTING = 0,
  10211. S_IDLE, = 1
  10212. S_AUTHORIZING, = 2
  10213. S_REASSIGN_CHECK, = 3
  10214. S_REASSIGN, = 4
  10215. S_PRECHARGE, = 5
  10216. S_PREPARING_FOR_EV, = 6
  10217. S_PREPARING_FOR_EVSE, = 7
  10218. S_CHARGING, = 8
  10219. S_TERMINATING, = 9
  10220. S_COMPLETE, = 10
  10221. S_ALARM, = 11
  10222. S_FAULT = 12
  10223. }
  10224. */
  10225. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10226. {
  10227. //check Transaction active
  10228. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10229. {
  10230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10231. {
  10232. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10233. }
  10234. else
  10235. {
  10236. tempIndex = connectorIdInt -1;
  10237. }
  10238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10239. {
  10240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10241. {
  10242. 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))
  10243. {
  10244. //Reserved
  10245. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10246. }
  10247. 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))
  10248. {
  10249. //Reserved
  10250. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10251. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10252. goto end;
  10253. }
  10254. else
  10255. {
  10256. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10257. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10258. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10259. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10260. {
  10261. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10263. goto end;
  10264. }
  10265. }//END FOR ELSE
  10266. }
  10267. }// END FOR CHAdeMO_QUANTITY
  10268. }
  10269. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10270. {
  10271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10272. {
  10273. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10274. }
  10275. else
  10276. {
  10277. tempIndex = connectorIdInt -1;
  10278. }
  10279. for (int index = 0; index < CCS_QUANTITY; index++)
  10280. {
  10281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10282. {
  10283. 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))
  10284. {
  10285. //Reserved
  10286. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10287. }
  10288. 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))
  10289. {
  10290. //Reserved
  10291. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10292. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10293. goto end;
  10294. }
  10295. else
  10296. {
  10297. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10298. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10299. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10300. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10301. {
  10302. DEBUG_WARN("CCS connector not allow start\n.");
  10303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10304. goto end;
  10305. }
  10306. }// END FOR ELSE
  10307. }
  10308. }// END FOR CCS_QUANTITY
  10309. }
  10310. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10311. {
  10312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10313. {
  10314. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10315. }
  10316. else
  10317. {
  10318. tempIndex = connectorIdInt -1;
  10319. }
  10320. for (int index = 0; index < GB_QUANTITY; index++)
  10321. {
  10322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10323. {
  10324. 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))
  10325. {
  10326. //Reserved
  10327. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10328. }
  10329. 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))
  10330. {
  10331. //Reserved
  10332. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10333. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10334. goto end;
  10335. }
  10336. else
  10337. {
  10338. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10339. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10340. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10341. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10342. {
  10343. DEBUG_WARN("GB connector not allow start\n.");
  10344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10345. goto end;
  10346. }
  10347. }// END FOR ELSE
  10348. }
  10349. } // END FOR GB_QUANTITY
  10350. }
  10351. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10352. {
  10353. tempIndex = connectorIdInt -1;
  10354. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10355. {
  10356. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10357. {
  10358. 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))
  10359. {
  10360. //Reserved
  10361. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10362. }
  10363. 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))
  10364. {
  10365. //Reserved
  10366. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10367. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10368. goto end;
  10369. }
  10370. else
  10371. {
  10372. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10373. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10374. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10375. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10376. {
  10377. DEBUG_WARN("GB connector not allow start\n.");
  10378. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10379. goto end;
  10380. }
  10381. }// END FOR ELSE
  10382. }
  10383. } // END FOR GB_QUANTITY
  10384. }
  10385. else
  10386. {
  10387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10388. {
  10389. tempIndex = 2;
  10390. }
  10391. else
  10392. {
  10393. tempIndex = connectorIdInt -1;
  10394. }
  10395. for (int index = 0; index < AC_QUANTITY; index++)
  10396. {
  10397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10398. {
  10399. 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))
  10400. {
  10401. //Reserved
  10402. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10403. }
  10404. 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))
  10405. {
  10406. //Reserved
  10407. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10408. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10409. goto end;
  10410. }
  10411. else
  10412. {
  10413. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10414. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10415. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10416. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10417. {
  10418. DEBUG_WARN("AC connector not allow start\n.");
  10419. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10420. goto end;
  10421. }
  10422. }//END FOR ELSE
  10423. }
  10424. }// END FOR AC_QUANTITY
  10425. }
  10426. if(chargingProfileIsNULL == FALSE)
  10427. {
  10428. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10429. {
  10430. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10432. //memset idTag
  10433. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10434. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10435. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10436. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10437. // Save profile to file
  10438. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10439. system(cmdBuf);
  10440. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10441. fp = fopen(cmdBuf, "w");
  10442. 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));
  10443. fclose(fp);
  10444. }
  10445. else
  10446. {
  10447. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10449. }
  10450. }
  10451. else
  10452. {
  10453. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10454. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10455. //memset idTag
  10456. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10457. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10458. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10460. }
  10461. }
  10462. else
  10463. {
  10464. DEBUG_WARN("Connector id over\n.");
  10465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10466. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10467. }
  10468. end:
  10469. json_object_put(RemoteStartTransaction);
  10470. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10471. {
  10472. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10473. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10474. }
  10475. //OCPP send RemoteStartConfirmation by first.
  10476. sendRemoteStartConfirmation(uuid, comfirmstr);
  10477. return result;
  10478. }
  10479. int handleRemoteStartRequest(char *uuid, char *payload)
  10480. {
  10481. mtrace();
  10482. int result = PASS;
  10483. int connectorIdInt=-1;
  10484. int tempIndex = 0;
  10485. char comfirmstr[20]={0};
  10486. char cmdBuf[512];
  10487. json_object *RemoteStartTransaction;
  10488. FILE *fp;
  10489. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10490. if(server_pending == TRUE)
  10491. {
  10492. result = FAIL;
  10493. }
  10494. RemoteStartTransaction = json_tokener_parse(payload);
  10495. if(!is_error(RemoteStartTransaction))
  10496. {
  10497. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10498. {
  10499. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10500. }
  10501. else
  10502. {
  10503. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10504. {
  10505. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10506. {
  10507. connectorIdInt = (gun_index+1);
  10508. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10509. break;
  10510. }
  10511. }
  10512. }
  10513. if(connectorIdInt == 0)
  10514. {
  10515. DEBUG_WARN("Connector id shall not equal 0.\n");
  10516. result = FAIL;
  10517. }
  10518. else if(connectorIdInt == -1)
  10519. {
  10520. DEBUG_INFO("Connector id does not specific.\n");
  10521. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10522. {
  10523. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10524. // Required data
  10525. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10526. // Optional data
  10527. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10528. {
  10529. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10530. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10531. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10532. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10533. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10534. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10535. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10536. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10537. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10538. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10539. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10540. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10541. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10542. {
  10543. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10544. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10545. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10546. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10547. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10548. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10549. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10550. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10551. {
  10552. 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++)
  10553. {
  10554. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10555. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10556. 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)
  10557. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10558. }
  10559. }
  10560. }
  10561. }
  10562. else
  10563. {
  10564. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10565. }
  10566. }
  10567. }
  10568. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10569. {
  10570. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10571. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10572. // Required data
  10573. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10574. // Optional data
  10575. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10576. {
  10577. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10578. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10579. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10580. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10581. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10582. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10583. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10584. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10585. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10586. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10587. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10590. {
  10591. 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")));
  10592. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10593. 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"));
  10594. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10595. 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"));
  10596. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10597. 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")));
  10598. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10599. {
  10600. 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++)
  10601. {
  10602. 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"));
  10603. 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"));
  10604. 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)
  10605. 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"));
  10606. }
  10607. }
  10608. }
  10609. }
  10610. else
  10611. {
  10612. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10613. }
  10614. }
  10615. else
  10616. {
  10617. DEBUG_WARN("Connector id is over maximun value.\n");
  10618. result = FAIL;
  10619. }
  10620. }
  10621. if(result == PASS)
  10622. {
  10623. if(connectorIdInt > 0)
  10624. {
  10625. //check Transaction active
  10626. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10627. {
  10628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10629. {
  10630. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10631. }
  10632. else
  10633. {
  10634. tempIndex = connectorIdInt -1;
  10635. }
  10636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10637. {
  10638. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10639. {
  10640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10642. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10643. {
  10644. //Reserved
  10645. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10646. }
  10647. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10648. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10649. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10650. {
  10651. //Reserved
  10652. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10653. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10654. goto end;
  10655. }
  10656. else
  10657. {
  10658. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10659. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10660. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10661. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10662. {
  10663. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10664. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10665. goto end;
  10666. }
  10667. }//END FOR ELSE
  10668. }
  10669. }// END FOR CHAdeMO_QUANTITY
  10670. }
  10671. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10672. {
  10673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10674. {
  10675. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10676. }
  10677. else
  10678. {
  10679. tempIndex = connectorIdInt -1;
  10680. }
  10681. for (int index = 0; index < CCS_QUANTITY; index++)
  10682. {
  10683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10684. {
  10685. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10686. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10687. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10688. {
  10689. //Reserved
  10690. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10691. }
  10692. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10693. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10694. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10695. {
  10696. //Reserved
  10697. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10699. goto end;
  10700. }
  10701. else
  10702. {
  10703. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10704. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10705. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10706. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10707. {
  10708. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10709. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10710. goto end;
  10711. }
  10712. }// END FOR ELSE
  10713. }
  10714. }// END FOR CCS_QUANTITY
  10715. }
  10716. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10717. {
  10718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10719. {
  10720. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10721. }
  10722. else
  10723. {
  10724. tempIndex = connectorIdInt -1;
  10725. }
  10726. for (int index = 0; index < GB_QUANTITY; index++)
  10727. {
  10728. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10729. {
  10730. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10731. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10732. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10733. {
  10734. //Reserved
  10735. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10736. }
  10737. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10739. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10740. {
  10741. //Reserved
  10742. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10744. goto end;
  10745. }
  10746. else
  10747. {
  10748. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10749. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10750. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10751. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10752. {
  10753. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10755. goto end;
  10756. }
  10757. }// END FOR ELSE
  10758. }
  10759. } // END FOR GB_QUANTITY
  10760. }
  10761. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10762. {
  10763. tempIndex = connectorIdInt -1;
  10764. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10765. {
  10766. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10767. {
  10768. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10769. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10770. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10771. {
  10772. //Reserved
  10773. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10774. }
  10775. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10776. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10777. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10778. {
  10779. //Reserved
  10780. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10782. goto end;
  10783. }
  10784. else
  10785. {
  10786. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10787. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10788. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10789. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10790. {
  10791. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10792. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10793. goto end;
  10794. }
  10795. }// END FOR ELSE
  10796. }
  10797. } // END FOR GB_QUANTITY
  10798. }
  10799. else
  10800. {
  10801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10802. {
  10803. tempIndex = 2;
  10804. }
  10805. else
  10806. {
  10807. tempIndex = connectorIdInt -1;
  10808. }
  10809. for (int index = 0; index < AC_QUANTITY; index++)
  10810. {
  10811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10812. {
  10813. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10814. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10815. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10816. {
  10817. //Reserved
  10818. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10819. }
  10820. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10821. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10822. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10823. {
  10824. //Reserved
  10825. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10826. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10827. goto end;
  10828. }
  10829. else
  10830. {
  10831. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10832. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10833. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10834. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10835. {
  10836. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10837. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10838. goto end;
  10839. }
  10840. }//END FOR ELSE
  10841. }
  10842. }// END FOR AC_QUANTITY
  10843. }
  10844. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10845. {
  10846. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10847. {
  10848. // Save profile to file
  10849. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10850. system(cmdBuf);
  10851. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10852. fp = fopen(cmdBuf, "w");
  10853. 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));
  10854. fclose(fp);
  10855. }
  10856. else
  10857. {
  10858. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10860. goto end;
  10861. }
  10862. }
  10863. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10864. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10865. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10866. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10867. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10869. }
  10870. else
  10871. {
  10872. uint8_t isHasIdleConnector = FALSE;
  10873. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10874. {
  10875. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10876. {
  10877. isHasIdleConnector = TRUE;
  10878. break;
  10879. }
  10880. }
  10881. if(isHasIdleConnector == TRUE)
  10882. {
  10883. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10884. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10885. {
  10886. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10887. {
  10888. // Save profile to file
  10889. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10890. system(cmdBuf);
  10891. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10892. fp = fopen(cmdBuf, "w");
  10893. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10894. fclose(fp);
  10895. refreshStartTimer(&clientTime.RemoteStartWait);
  10896. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10897. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10898. }
  10899. else
  10900. {
  10901. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10902. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10903. }
  10904. }
  10905. else
  10906. {
  10907. refreshStartTimer(&clientTime.RemoteStartWait);
  10908. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10910. }
  10911. }
  10912. else
  10913. {
  10914. DEBUG_INFO("There is not any connector is idle.\n");
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10916. }
  10917. }
  10918. }
  10919. else
  10920. {
  10921. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10922. }
  10923. end:
  10924. json_object_put(RemoteStartTransaction);
  10925. sendRemoteStartConfirmation(uuid, comfirmstr);
  10926. return result;
  10927. }
  10928. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10929. {
  10930. mtrace();
  10931. int result = FAIL;
  10932. int match = FALSE;
  10933. int GunNO = 0;
  10934. int tempIndex = 0;
  10935. int transactionIdInt=0;
  10936. int transactionIdIsNULL= TRUE;
  10937. char comfirmstr[20];
  10938. json_object *RemoteStopTransaction;
  10939. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10940. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10941. if(server_pending == TRUE)
  10942. {
  10943. return 0;
  10944. }
  10945. RemoteStopTransaction = json_tokener_parse(payload);
  10946. if(!is_error(RemoteStopTransaction))
  10947. {
  10948. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10949. {
  10950. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10951. transactionIdIsNULL = FALSE;
  10952. }
  10953. }
  10954. json_object_put(RemoteStopTransaction);
  10955. if(transactionIdIsNULL == FALSE)
  10956. {
  10957. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10958. {
  10959. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10960. {
  10961. //check Transaction active
  10962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10963. {
  10964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10965. {
  10966. tempIndex = ((gun_index==2) ? 1: 0);
  10967. }
  10968. else
  10969. {
  10970. tempIndex = gun_index;
  10971. }
  10972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10973. {
  10974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10975. {
  10976. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10977. {
  10978. match = TRUE;
  10979. GunNO = gun_index;
  10980. }
  10981. }
  10982. }// END FOR CHAdeMO_QUANTITY
  10983. }
  10984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10985. {
  10986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10987. {
  10988. tempIndex = ((gun_index==2) ? 1: 0);
  10989. }
  10990. else
  10991. {
  10992. tempIndex = gun_index;
  10993. }
  10994. for (int index = 0; index < CCS_QUANTITY; index++)
  10995. {
  10996. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10997. {
  10998. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10999. {
  11000. match = TRUE;
  11001. GunNO = gun_index;
  11002. }
  11003. }
  11004. }// END FOR CCS_QUANTITY
  11005. }
  11006. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11007. {
  11008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11009. {
  11010. tempIndex = ((gun_index==2) ? 1: 0);
  11011. }
  11012. else
  11013. {
  11014. tempIndex = gun_index;
  11015. }
  11016. for (int index = 0; index < GB_QUANTITY; index++)
  11017. {
  11018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11019. {
  11020. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11021. {
  11022. match = TRUE;
  11023. GunNO = gun_index;
  11024. }
  11025. }
  11026. }// END FOR GB_QUANTITY
  11027. }
  11028. else if(gunType[gun_index] == GUN_TYPE_DO)
  11029. {
  11030. tempIndex = gun_index;
  11031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11032. {
  11033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11034. {
  11035. 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
  11036. {
  11037. match = TRUE;
  11038. GunNO = gun_index;
  11039. }
  11040. }
  11041. }// END FOR GB_QUANTITY
  11042. }
  11043. else
  11044. {
  11045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11046. {
  11047. tempIndex = 2;
  11048. }
  11049. else
  11050. {
  11051. tempIndex = gun_index;
  11052. }
  11053. for (int index = 0; index < AC_QUANTITY; index++)
  11054. {
  11055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11056. {
  11057. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11058. {
  11059. match = TRUE;
  11060. GunNO = gun_index;
  11061. }
  11062. }
  11063. }// END FOR CHAdeMO_QUANTITY
  11064. } // END FOR AC ELSE
  11065. }// CHECK IF ResponseTransactionId == transactionIdInt
  11066. }//END FOR
  11067. if( match == TRUE)
  11068. {
  11069. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11071. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11072. }
  11073. else
  11074. {
  11075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11076. }
  11077. }
  11078. else
  11079. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11080. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11081. return result;
  11082. }
  11083. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11084. {
  11085. mtrace();
  11086. int result = FAIL;
  11087. int connectorIdInt=0, reservationIdInt=0;
  11088. int tempIndex = 0;
  11089. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11090. char comfirmstr[20]={0};
  11091. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11092. int c = 0;
  11093. char *loc;
  11094. //char *ptr;
  11095. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11096. strcpy(sstrtemp, stringtrimspace(payload));
  11097. //***(1)connectorId ****/
  11098. c=0;
  11099. loc = strstr(sstrtemp, "connectorId");
  11100. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11101. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11102. {
  11103. sstr[c] = loc[strlen("connectorId")+2+c];
  11104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11105. c++;
  11106. }
  11107. sstr[c] = '\0';
  11108. connectorIdInt = atoi(sstr);
  11109. //***(2)expiryDate ****/
  11110. loc = strstr(sstrtemp, "expiryDate");
  11111. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11112. c = 0;
  11113. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11114. {
  11115. sstr[c] = loc[3+strlen("expiryDate")+c];
  11116. c++;
  11117. }
  11118. sstr[c] = '\0';
  11119. strcpy(expiryDatestr, sstr);
  11120. //***(3)idTag ****/
  11121. loc = strstr(sstrtemp, "idTag");
  11122. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11123. c = 0;
  11124. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11125. {
  11126. sstr[c] = loc[3+strlen("idTag")+c];
  11127. c++;
  11128. }
  11129. sstr[c] = '\0';
  11130. strcpy(idTagstr, sstr);
  11131. //***(4)parentIdTag ****/
  11132. loc = strstr(sstrtemp, "parentIdTag");
  11133. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11134. c = 0;
  11135. if(loc == NULL)
  11136. {
  11137. strcpy(parentIdTagstr, "");
  11138. }
  11139. else
  11140. {
  11141. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11142. {
  11143. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11144. c++;
  11145. }
  11146. sstr[c] = '\0';
  11147. strcpy(parentIdTagstr, sstr);
  11148. }
  11149. //***(5)reservationId ****/
  11150. c=0;
  11151. loc = strstr(sstrtemp, "reservationId");
  11152. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11153. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11154. {
  11155. sstr[c] = loc[strlen("reservationId")+2+c];
  11156. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11157. c++;
  11158. }
  11159. sstr[c] = '\0';
  11160. reservationIdInt = atoi(sstr);
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11162. /*
  11163. enum SYSTEM_STATUS
  11164. {
  11165. SYS_MODE_BOOTING = 0,
  11166. SYS_MODE_IDLE = 1,
  11167. SYS_MODE_AUTHORIZING = 2,
  11168. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11169. SYS_MODE_REASSIGN = 4,
  11170. SYS_MODE_PREPARING = 5,
  11171. SYS_MODE_PREPARE_FOR_EV = 6,
  11172. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11173. SYS_MODE_CHARGING = 8,
  11174. SYS_MODE_TERMINATING = 9,
  11175. SYS_MODE_COMPLETE = 10,
  11176. SYS_MODE_ALARM = 11,
  11177. SYS_MODE_FAULT = 12,
  11178. SYS_MODE_RESERVATION = 13,
  11179. SYS_MODE_BOOKING = 14,
  11180. SYS_MODE_MAINTAIN = 15,
  11181. SYS_MODE_DEBUG = 16,
  11182. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11183. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11184. SYS_MODE_UPDATE = 19
  11185. };
  11186. */
  11187. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11190. goto end;
  11191. }
  11192. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11193. {
  11194. //check Transaction active
  11195. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11196. {
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11198. {
  11199. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11200. }
  11201. else
  11202. {
  11203. tempIndex = connectorIdInt -1;
  11204. }
  11205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11206. {
  11207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11208. {
  11209. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11210. {
  11211. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11212. {
  11213. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11214. {
  11215. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11217. }
  11218. 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'))
  11219. {
  11220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11221. }
  11222. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11223. {
  11224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11225. }
  11226. else
  11227. {
  11228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11229. }
  11230. }
  11231. 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
  11232. {
  11233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11234. }
  11235. }
  11236. else
  11237. {
  11238. //replace reservation
  11239. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11241. }
  11242. }
  11243. } // END FOR CHAdeMO_QUANTITY
  11244. }
  11245. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11246. {
  11247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11248. {
  11249. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11250. }
  11251. else
  11252. {
  11253. tempIndex = connectorIdInt -1;
  11254. }
  11255. for (int index = 0; index < CCS_QUANTITY; index++)
  11256. {
  11257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11258. {
  11259. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11260. {
  11261. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11262. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11263. {
  11264. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11265. {
  11266. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11268. }
  11269. 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'))
  11270. {
  11271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11272. }
  11273. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11274. {
  11275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11276. }
  11277. else
  11278. {
  11279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11280. }
  11281. }
  11282. 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
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11285. }
  11286. }
  11287. else
  11288. {
  11289. //replace reservation
  11290. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11292. }
  11293. }
  11294. } // END FOR CCS_QUANTITY
  11295. }
  11296. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11297. {
  11298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11299. {
  11300. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11301. }
  11302. else
  11303. {
  11304. tempIndex = connectorIdInt -1;
  11305. }
  11306. for (int index = 0; index < GB_QUANTITY; index++)
  11307. {
  11308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11309. {
  11310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11311. {
  11312. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11313. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11314. {
  11315. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11316. {
  11317. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11319. }
  11320. 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'))
  11321. {
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11323. }
  11324. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11325. {
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11327. }
  11328. else
  11329. {
  11330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11331. }
  11332. }
  11333. 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
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11336. }
  11337. }
  11338. else
  11339. {
  11340. //replace reservation
  11341. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11343. }
  11344. }
  11345. }// END FOR GB_QUANTITY
  11346. }
  11347. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11348. {
  11349. tempIndex = connectorIdInt -1;
  11350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11351. {
  11352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11353. {
  11354. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11355. {
  11356. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11357. 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
  11358. {
  11359. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11360. {
  11361. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11362. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11363. }
  11364. 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'))
  11365. {
  11366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11367. }
  11368. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11369. {
  11370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11371. }
  11372. else
  11373. {
  11374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11375. }
  11376. }
  11377. 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
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11380. }
  11381. }
  11382. else
  11383. {
  11384. //replace reservation
  11385. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11387. }
  11388. }
  11389. }// END FOR GB_QUANTITY
  11390. }
  11391. else
  11392. {
  11393. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11394. {
  11395. tempIndex = 2;
  11396. }
  11397. else
  11398. {
  11399. tempIndex = (connectorIdInt -1);
  11400. }
  11401. for (int index = 0; index < AC_QUANTITY; index++)
  11402. {
  11403. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11404. {
  11405. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11406. {
  11407. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11408. {
  11409. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11410. {
  11411. 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))
  11412. {
  11413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11414. }
  11415. else
  11416. {
  11417. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11419. }
  11420. }
  11421. 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'))
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11424. }
  11425. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11428. }
  11429. else
  11430. {
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11432. }
  11433. }
  11434. 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
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11437. }
  11438. }
  11439. else
  11440. {
  11441. //replace reservation
  11442. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11444. }
  11445. }
  11446. } // END FOR AC_QUANTITY
  11447. }
  11448. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11449. }
  11450. else if(connectorIdInt == 0)
  11451. {
  11452. //check Transaction active
  11453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11454. {
  11455. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11456. {
  11457. 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'))
  11458. {
  11459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11460. goto end;
  11461. }
  11462. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11463. {
  11464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11465. goto end;
  11466. }
  11467. 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
  11468. {
  11469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11470. goto end;
  11471. }
  11472. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11475. goto end;
  11476. }
  11477. }
  11478. }// END FOR CHAdeMO_QUANTITY
  11479. for (int index = 0; index < CCS_QUANTITY; index++)
  11480. {
  11481. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11482. {
  11483. 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'))
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11486. goto end;
  11487. }
  11488. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11491. goto end;
  11492. }
  11493. 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
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11496. goto end;
  11497. }
  11498. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11499. {
  11500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11501. goto end;
  11502. }
  11503. }
  11504. } // END FOR CCS_QUANTITY
  11505. for (int index = 0; index < GB_QUANTITY; index++)
  11506. {
  11507. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11508. {
  11509. 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'))
  11510. {
  11511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11512. goto end;
  11513. }
  11514. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11515. {
  11516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11517. goto end;
  11518. }
  11519. 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
  11520. {
  11521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11522. goto end;
  11523. }
  11524. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11527. goto end;
  11528. }
  11529. }
  11530. } // END FOR GB_QUANTITY
  11531. for (int index = 0; index < AC_QUANTITY; index++)
  11532. {
  11533. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11534. {
  11535. 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'))
  11536. {
  11537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11538. goto end;
  11539. }
  11540. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11543. goto end;
  11544. }
  11545. 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
  11546. {
  11547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11548. goto end;
  11549. }
  11550. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11551. {
  11552. 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))
  11553. {
  11554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11555. goto end;
  11556. }
  11557. }
  11558. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11559. {
  11560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11561. goto end;
  11562. }
  11563. }
  11564. }// END FOR AC_QUANTITY
  11565. //The connectorId is 0
  11566. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11568. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11569. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11570. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11571. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11572. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11573. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11574. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11575. result = TRUE;
  11576. return result;
  11577. }
  11578. else
  11579. {
  11580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11581. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11582. }
  11583. if(strcmp(comfirmstr,"Accepted") == 0)
  11584. {
  11585. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11586. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11587. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11588. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11589. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11590. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11591. result = TRUE;
  11592. return result;
  11593. }
  11594. end:
  11595. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11596. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11597. return result;
  11598. }
  11599. int handleResetRequest(char *uuid, char *payload)
  11600. {
  11601. mtrace();
  11602. int result = FAIL;
  11603. char sstr[10]={0},sstrtemp[30]={ 0 };
  11604. char typestr[10]={0};
  11605. char comfirmstr[20]={0};
  11606. int c = 0;
  11607. char *loc;
  11608. DEBUG_INFO("handleResetRequest...\n");
  11609. strcpy(sstrtemp, stringtrimspace(payload));
  11610. loc = strstr(sstrtemp, "type");
  11611. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11612. c = 0;
  11613. while (loc[3+strlen("type")+c] != '\"')
  11614. {
  11615. sstr[c] = loc[3+strlen("type")+c];
  11616. c++;
  11617. }
  11618. sstr[c] = '\0';
  11619. strcpy(typestr,sstr);
  11620. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11621. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11622. {
  11623. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11624. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11625. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11626. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11627. }
  11628. else
  11629. {
  11630. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11631. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11632. result = PASS;
  11633. }
  11634. sendResetConfirmation(uuid, comfirmstr);
  11635. return result;
  11636. }
  11637. int handleSendLocalListRequest(char *uuid, char *payload)
  11638. {
  11639. mtrace();
  11640. int result = FAIL;
  11641. char comfirmstr[20];
  11642. int checkState_Faulted = FALSE;
  11643. json_object *SendLocalList;
  11644. DEBUG_INFO("handleSendLocalListRequest...\n");
  11645. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11646. {
  11647. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11648. goto end;
  11649. }
  11650. //check Charge Point state
  11651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11652. {
  11653. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11654. {
  11655. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11656. }
  11657. }
  11658. for (int index = 0; index < CCS_QUANTITY; index++)
  11659. {
  11660. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11661. {
  11662. checkState_Faulted = TRUE; //OCPP Status
  11663. }
  11664. }
  11665. for (int index = 0; index < GB_QUANTITY; index++)
  11666. {
  11667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11668. {
  11669. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11670. }
  11671. }
  11672. //check Charge Point state
  11673. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11674. {
  11675. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11676. {
  11677. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11678. }
  11679. }
  11680. //check Charge Point state
  11681. for (int index = 0; index < AC_QUANTITY; index++)
  11682. {
  11683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11684. {
  11685. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11686. }
  11687. }
  11688. if(checkState_Faulted == TRUE)
  11689. {
  11690. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11691. goto end;
  11692. }
  11693. // Parsing payload
  11694. SendLocalList = json_tokener_parse(payload);
  11695. if(!is_error(SendLocalList))
  11696. {
  11697. // Required data
  11698. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11699. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11700. // Optional data
  11701. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11702. {
  11703. //Check UpdateType
  11704. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11705. {
  11706. //Local list full update
  11707. DEBUG_INFO("Local list full update.\n");
  11708. locallistVersion = 0;
  11709. OCPP_getListVerion();
  11710. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11711. {
  11712. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11713. goto end;
  11714. }*/
  11715. OCPP_cleanLocalList();
  11716. }
  11717. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11718. {
  11719. //Local list different update
  11720. DEBUG_INFO("Local list different update.\n");
  11721. locallistVersion = 0;
  11722. OCPP_getListVerion();
  11723. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11724. {
  11725. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11726. goto end;
  11727. }
  11728. }
  11729. else
  11730. {
  11731. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11732. goto end;
  11733. }
  11734. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11735. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11736. {
  11737. 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")));
  11738. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11739. {
  11740. 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")));
  11741. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11742. 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")));
  11743. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11744. 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")));
  11745. }
  11746. // Add to db
  11747. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11748. {
  11749. //Local list full update
  11750. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11751. idx,
  11752. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11753. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11754. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11755. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11756. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11757. // update list
  11758. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11759. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11760. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11761. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11762. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11763. }
  11764. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11765. {
  11766. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11767. idx,
  11768. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11769. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11770. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11771. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11772. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11773. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11774. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11775. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11776. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11777. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11778. }
  11779. }
  11780. }
  11781. else
  11782. {
  11783. //Check UpdateType
  11784. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11785. {
  11786. //Local list full update
  11787. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11788. OCPP_cleanLocalList();
  11789. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11790. goto end;
  11791. }
  11792. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11793. {
  11794. //Local list different update
  11795. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11796. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11797. goto end;
  11798. }
  11799. }
  11800. result = PASS;
  11801. }
  11802. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11803. end:
  11804. json_object_put(SendLocalList);
  11805. sendSendLocalListConfirmation(uuid, comfirmstr);
  11806. return result;
  11807. }
  11808. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11809. {
  11810. mtrace();
  11811. int result = FAIL;
  11812. struct StructSetChargingProfile SetProfileReq = {0};
  11813. int tempchargingProfileIdInt;
  11814. int tempstackLevelInt;
  11815. int chargingSchedulePeriodCount = 0;
  11816. char comfirmstr[20]={0};
  11817. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11818. char rmFileCmd[128]={0};
  11819. int profileQuantity = 0;
  11820. int replaceableProfileCnt = 0;
  11821. json_object *SetChargingProfile;
  11822. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11823. SetChargingProfile = json_tokener_parse(payload);
  11824. if(!is_error(SetChargingProfile))
  11825. {
  11826. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11827. {
  11828. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11829. }
  11830. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11831. {
  11832. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11833. {
  11834. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11835. }
  11836. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11837. {
  11838. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11839. }
  11840. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11841. {
  11842. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11843. }
  11844. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11845. {
  11846. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11847. }
  11848. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11849. {
  11850. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11851. }
  11852. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11853. {
  11854. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11855. }
  11856. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11857. {
  11858. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11859. }
  11860. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11861. {
  11862. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11863. }
  11864. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11865. {
  11866. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11867. {
  11868. 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")));
  11869. }
  11870. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11871. {
  11872. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11873. }
  11874. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11875. {
  11876. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11877. }
  11878. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11879. {
  11880. 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")));
  11881. }
  11882. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11883. {
  11884. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11885. if(chargingSchedulePeriodCount <= 10)
  11886. {
  11887. 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++)
  11888. {
  11889. 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)
  11890. {
  11891. 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"));
  11892. }
  11893. 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)
  11894. {
  11895. 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"));
  11896. }
  11897. 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)
  11898. {
  11899. 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"));
  11900. }
  11901. }
  11902. }
  11903. }
  11904. }
  11905. }
  11906. }
  11907. // Profile periods quantity check
  11908. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11909. {
  11910. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11911. goto end;
  11912. }
  11913. // Check invalid limit
  11914. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11915. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11916. {
  11917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11918. {
  11919. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11920. {
  11921. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11922. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11923. {
  11924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11925. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11927. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11928. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11929. goto end;
  11930. }
  11931. }
  11932. }
  11933. else
  11934. {
  11935. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11936. {
  11937. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  11938. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  11939. {
  11940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11941. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11942. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11943. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11944. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11945. goto end;
  11946. }
  11947. }
  11948. }
  11949. }
  11950. // Profile purpose info check
  11951. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11952. {
  11953. FILE *fp;
  11954. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11955. if(SetProfileReq.ConnectorId != 0)
  11956. {
  11957. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11958. goto end;
  11959. }
  11960. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11961. if (!fp)
  11962. {
  11963. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11964. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11965. }
  11966. else
  11967. {
  11968. char *line = NULL;
  11969. size_t len = 0;
  11970. while(getline(&line, &len, fp) != -1)
  11971. {
  11972. json_object *obj = NULL;
  11973. obj = json_tokener_parse(line);
  11974. if(is_error(obj))
  11975. {
  11976. DEBUG_ERROR("Parse txProfile from file error.\n");
  11977. }
  11978. else
  11979. {
  11980. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11981. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11982. {
  11983. profileQuantity += 1;
  11984. }
  11985. else
  11986. replaceableProfileCnt += 1;
  11987. }
  11988. }
  11989. }
  11990. fclose(fp);
  11991. }
  11992. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11993. {
  11994. FILE *fp;
  11995. char filename[128]={0};
  11996. int tmpProfileQuantity;
  11997. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11998. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11999. {
  12000. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12001. goto end;
  12002. }
  12003. if(SetProfileReq.ConnectorId == 0)
  12004. {
  12005. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12006. {
  12007. tmpProfileQuantity = 0;
  12008. memset(filename, 0, ARRAY_SIZE(filename));
  12009. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12010. fp = fopen(filename, "r");
  12011. if (!fp)
  12012. {
  12013. DEBUG_INFO("%s does not create.\n", filename);
  12014. fp = fopen(filename, "w+");
  12015. }
  12016. else
  12017. {
  12018. char *line = NULL;
  12019. size_t len = 0;
  12020. while(getline(&line, &len, fp) != -1)
  12021. {
  12022. json_object *obj = NULL;
  12023. obj = json_tokener_parse(line);
  12024. if(is_error(obj))
  12025. {
  12026. DEBUG_ERROR("Parse txProfile from file error.\n");
  12027. }
  12028. else
  12029. {
  12030. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12031. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12032. {
  12033. tmpProfileQuantity += 1;
  12034. }
  12035. else
  12036. replaceableProfileCnt += 1;
  12037. }
  12038. }
  12039. }
  12040. fclose(fp);
  12041. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12042. }
  12043. }
  12044. else
  12045. {
  12046. memset(filename, 0, ARRAY_SIZE(filename));
  12047. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12048. fp = fopen(filename, "r");
  12049. if (!fp)
  12050. {
  12051. DEBUG_INFO("%s does not create.\n", filename);
  12052. fp = fopen(filename, "w+");
  12053. }
  12054. else
  12055. {
  12056. char *line = NULL;
  12057. size_t len = 0;
  12058. while(getline(&line, &len, fp) != -1)
  12059. {
  12060. json_object *obj = NULL;
  12061. obj = json_tokener_parse(line);
  12062. if(is_error(obj))
  12063. {
  12064. DEBUG_ERROR("Parse txProfile from file error.\n");
  12065. }
  12066. else
  12067. {
  12068. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12069. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12070. {
  12071. profileQuantity += 1;
  12072. }
  12073. else
  12074. replaceableProfileCnt += 1;
  12075. }
  12076. }
  12077. }
  12078. fclose(fp);
  12079. }
  12080. }
  12081. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12082. {
  12083. int isMatchTransactiodId= FALSE;
  12084. FILE *fp;
  12085. char filename[128]={0};
  12086. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12087. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12088. if(SetProfileReq.ConnectorId == 0)
  12089. {
  12090. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12091. goto end;
  12092. }
  12093. int tempIndex = 0;
  12094. //check Transaction active
  12095. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12096. {
  12097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12098. {
  12099. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12100. }
  12101. else
  12102. {
  12103. tempIndex = SetProfileReq.ConnectorId -1;
  12104. }
  12105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12106. {
  12107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12108. {
  12109. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12110. {
  12111. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12112. {
  12113. isMatchTransactiodId = TRUE;
  12114. break;
  12115. }
  12116. }
  12117. }
  12118. }
  12119. }
  12120. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12121. {
  12122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12123. {
  12124. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12125. }
  12126. else
  12127. {
  12128. tempIndex = SetProfileReq.ConnectorId -1;
  12129. }
  12130. for (int index = 0; index < CCS_QUANTITY; index++)
  12131. {
  12132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12133. {
  12134. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12135. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12136. {
  12137. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12138. {
  12139. isMatchTransactiodId = TRUE;
  12140. break;
  12141. }
  12142. }
  12143. }
  12144. }
  12145. }
  12146. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12147. {
  12148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12149. {
  12150. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12151. }
  12152. else
  12153. {
  12154. tempIndex = SetProfileReq.ConnectorId -1;
  12155. }
  12156. for (int index = 0; index < GB_QUANTITY; index++)
  12157. {
  12158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12159. {
  12160. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12161. {
  12162. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12163. {
  12164. isMatchTransactiodId = TRUE;
  12165. break;
  12166. }
  12167. }
  12168. }
  12169. }
  12170. }
  12171. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12172. {
  12173. tempIndex = SetProfileReq.ConnectorId -1;
  12174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12175. {
  12176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12177. {
  12178. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12179. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12180. {
  12181. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12182. {
  12183. isMatchTransactiodId = TRUE;
  12184. break;
  12185. }
  12186. }
  12187. }
  12188. }
  12189. }
  12190. else
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12193. {
  12194. tempIndex = 2;
  12195. }
  12196. else
  12197. {
  12198. tempIndex = (SetProfileReq.ConnectorId -1);
  12199. }
  12200. for (int index = 0; index < AC_QUANTITY; index++)
  12201. {
  12202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12203. {
  12204. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12205. {
  12206. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12207. {
  12208. isMatchTransactiodId = TRUE;
  12209. break;
  12210. }
  12211. }
  12212. }
  12213. }
  12214. }
  12215. //check Transaction active
  12216. if(isMatchTransactiodId == FALSE)
  12217. {
  12218. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12219. goto end;
  12220. }
  12221. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12222. {
  12223. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12224. goto end;
  12225. }
  12226. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12227. fp = fopen(filename, "r");
  12228. if (!fp)
  12229. {
  12230. DEBUG_INFO("%s does not create.\n", filename);
  12231. fp = fopen(filename, "w+");
  12232. }
  12233. else
  12234. {
  12235. char *line = NULL;
  12236. size_t len = 0;
  12237. while(getline(&line, &len, fp) != -1)
  12238. {
  12239. json_object *obj = NULL;
  12240. obj = json_tokener_parse(line);
  12241. if(is_error(obj))
  12242. {
  12243. DEBUG_ERROR("Parse txProfile from file error.\n");
  12244. }
  12245. else
  12246. {
  12247. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12248. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12249. {
  12250. profileQuantity += 1;
  12251. }
  12252. else
  12253. replaceableProfileCnt += 1;
  12254. }
  12255. }
  12256. }
  12257. fclose(fp);
  12258. }
  12259. // Check ChargeProfileMaxStackLevel
  12260. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12261. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12262. {
  12263. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12264. goto end;
  12265. }
  12266. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12267. {
  12268. FILE *fp;
  12269. char dataLine[4096]={0};
  12270. char fnametemp[128]={0};
  12271. int tmpProfileQuantity;
  12272. //Check ChargePointMaxProfile.json exit
  12273. profileQuantity = 0;
  12274. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12275. {
  12276. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12277. //Check Charging Profile Count
  12278. tmpProfileQuantity = 0;
  12279. while(fscanf(fp, "%s", dataLine) != EOF)
  12280. {
  12281. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12282. {
  12283. profileQuantity += 1;
  12284. tmpProfileQuantity += 1;
  12285. }
  12286. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12287. }
  12288. fclose(fp);
  12289. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12290. }
  12291. //Check TxDefaultProfile_%d.json
  12292. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12293. {
  12294. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12295. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12296. if((access(fnametemp,F_OK))!=-1)
  12297. {
  12298. fp = fopen(fnametemp, "r");
  12299. //Check Charging Profile Count
  12300. tmpProfileQuantity = 0;
  12301. while(fscanf(fp, "%s", dataLine) != EOF)
  12302. {
  12303. //DEBUG_INFO("word=%s\n",word);
  12304. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12305. {
  12306. profileQuantity += 1;
  12307. tmpProfileQuantity += 1;
  12308. }
  12309. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12310. }
  12311. fclose(fp);
  12312. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12313. }
  12314. }
  12315. //Check TxProfile_%d.json
  12316. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12317. {
  12318. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12319. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12320. if((access(fnametemp,F_OK))!=-1)
  12321. {
  12322. fp = fopen(fnametemp, "r");
  12323. //Check Charging Profile Count
  12324. tmpProfileQuantity = 0;
  12325. while(fscanf(fp, "%s", dataLine) != EOF)
  12326. {
  12327. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12328. {
  12329. profileQuantity += 1;
  12330. tmpProfileQuantity += 1;
  12331. }
  12332. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12333. }
  12334. fclose(fp);
  12335. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12336. }
  12337. }
  12338. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12339. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12340. // To check total Profile quantity
  12341. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12342. {
  12343. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12344. {
  12345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12346. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12347. goto end;
  12348. }
  12349. }
  12350. else
  12351. {
  12352. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12353. {
  12354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12355. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12356. goto end;
  12357. }
  12358. }
  12359. }
  12360. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12361. //**********************************Write to File********************************************************/
  12362. {
  12363. FILE *infile;
  12364. FILE *outfile;
  12365. char dataLine[4096]={0};
  12366. char filename[128]={0};
  12367. int chkChar=0;
  12368. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12369. {
  12370. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12371. {
  12372. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12373. }
  12374. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12375. {
  12376. if(SetProfileReq.ConnectorId==0)
  12377. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12378. else
  12379. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12380. }
  12381. else
  12382. {
  12383. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12384. }
  12385. infile = fopen (filename, "r");
  12386. outfile = fopen (tempfile, "w");
  12387. chkChar = fgetc(infile);
  12388. rewind(infile);
  12389. if(chkChar == EOF)
  12390. {
  12391. // Profile is empty
  12392. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12393. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12394. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12395. fclose(infile);
  12396. fclose(outfile);
  12397. sprintf(rmFileCmd,"rm -f %s",filename);
  12398. system(rmFileCmd);
  12399. rename(tempfile, filename);
  12400. }
  12401. else
  12402. {
  12403. // Profile is not empty
  12404. int ChargingProfileAdded = FALSE;
  12405. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12406. {
  12407. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12408. json_object *tmpChargingProfile;
  12409. tmpChargingProfile = json_tokener_parse(dataLine);
  12410. if(!is_error(SetChargingProfile))
  12411. {
  12412. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12413. {
  12414. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12415. {
  12416. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12417. }
  12418. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12419. {
  12420. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12421. }
  12422. }
  12423. }
  12424. json_object_put(tmpChargingProfile);
  12425. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12426. {
  12427. if(ChargingProfileAdded == FALSE)
  12428. {
  12429. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12430. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12431. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12432. ChargingProfileAdded = TRUE;
  12433. }
  12434. }
  12435. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12436. {
  12437. if(ChargingProfileAdded == FALSE)
  12438. {
  12439. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12440. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12441. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12442. ChargingProfileAdded = TRUE;
  12443. }
  12444. }
  12445. else
  12446. {
  12447. fprintf(outfile,"%s\n",dataLine);
  12448. if(ChargingProfileAdded == FALSE)
  12449. {
  12450. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12451. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12452. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12453. ChargingProfileAdded = TRUE;
  12454. }
  12455. }
  12456. } // end of while loop
  12457. fclose(infile);
  12458. fclose(outfile);
  12459. sprintf(rmFileCmd,"rm -f %s",filename);
  12460. system(rmFileCmd);
  12461. rename(tempfile, filename);
  12462. }
  12463. }
  12464. sleep(1);
  12465. result = TRUE;
  12466. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12467. }
  12468. end:
  12469. json_object_put(SetChargingProfile);
  12470. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12471. {
  12472. if(SetProfileReq.ConnectorId == 0)
  12473. {
  12474. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12475. {
  12476. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12477. }
  12478. }
  12479. else
  12480. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12481. }
  12482. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12483. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12484. return result;
  12485. }
  12486. int handleTriggerMessageRequest(char *uuid, char *payload)
  12487. {
  12488. mtrace();
  12489. int result = FAIL;
  12490. int connectorIdIsNULL = FALSE;
  12491. int connectorIdInt =0;
  12492. char sstr[40]={0},sstrtemp[100]={ 0 };
  12493. char requestedMessagestr[40]={0};
  12494. char comfirmstr[20]={0};
  12495. int c = 0;
  12496. char *loc;
  12497. DEBUG_INFO("handleTriggerMessageRequest\n");
  12498. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12499. strcpy(sstrtemp, stringtrimspace(payload));
  12500. c = 0;
  12501. loc = strstr(sstrtemp, "requestedMessage");
  12502. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12503. {
  12504. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12505. c++;
  12506. }
  12507. sstr[c] = '\0';
  12508. strcpy(requestedMessagestr, sstr);
  12509. c = 0;
  12510. loc = strstr(sstrtemp, "connectorId");
  12511. if(loc == NULL)
  12512. {
  12513. connectorIdIsNULL = TRUE;
  12514. }
  12515. else
  12516. {
  12517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12518. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12519. {
  12520. sstr[c] = loc[strlen("connectorId")+2+c];
  12521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12522. c++;
  12523. }
  12524. sstr[c] = '\0';
  12525. connectorIdInt = atoi(sstr);
  12526. }
  12527. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12528. {
  12529. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12530. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12531. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12532. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12533. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12534. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12535. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12536. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12537. {
  12538. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12539. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12540. return TRUE;
  12541. }
  12542. else
  12543. {
  12544. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12545. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12546. }
  12547. }
  12548. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12549. {
  12550. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12551. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12552. return TRUE;
  12553. }
  12554. //==========================
  12555. // Trigger message
  12556. //==========================
  12557. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12558. {
  12559. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12560. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12561. {
  12562. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12563. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12564. }
  12565. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12566. }
  12567. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12568. {
  12569. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12570. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12571. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12572. }
  12573. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12574. {
  12575. //sendBootNotificationRequest();
  12576. server_sign = FALSE;
  12577. }
  12578. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12579. {
  12580. refreshStartTimer(&clientTime.Heartbeat);
  12581. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12582. }
  12583. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12584. {
  12585. if(connectorIdIsNULL == FALSE)
  12586. {
  12587. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12588. {
  12589. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12590. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12591. }
  12592. }
  12593. else
  12594. {
  12595. for(int idx=0;idx< gunTotalNumber;idx++)
  12596. {
  12597. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12598. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12599. }
  12600. }
  12601. }
  12602. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12603. {
  12604. if(connectorIdIsNULL == FALSE)
  12605. {
  12606. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12607. {
  12608. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12609. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12610. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12611. }
  12612. }
  12613. else
  12614. {
  12615. for(int idx=0;idx< gunTotalNumber;idx++)
  12616. {
  12617. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12618. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12619. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12620. }
  12621. }
  12622. }
  12623. return result;
  12624. }
  12625. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12626. {
  12627. mtrace();
  12628. int result = FAIL;
  12629. int connectorIdInt =0;
  12630. char comfirmstr[20]={0};
  12631. int tempIndex = 0;
  12632. json_object *UnlockConnector;
  12633. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12634. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12635. UnlockConnector = json_tokener_parse(payload);
  12636. if(!is_error(UnlockConnector))
  12637. {
  12638. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12639. {
  12640. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12641. }
  12642. }
  12643. json_object_put(UnlockConnector);
  12644. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12645. if(gunTotalNumber == 0)
  12646. {
  12647. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12648. goto end;
  12649. }
  12650. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12651. {
  12652. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12653. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12654. goto end;
  12655. }
  12656. else
  12657. {
  12658. //check Transaction active
  12659. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12660. {
  12661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12662. {
  12663. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12664. }
  12665. else
  12666. {
  12667. tempIndex = connectorIdInt -1;
  12668. }
  12669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12670. {
  12671. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12672. {
  12673. //stop Transaction
  12674. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12675. }
  12676. }
  12677. }
  12678. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12679. {
  12680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12681. {
  12682. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12683. }
  12684. else
  12685. {
  12686. tempIndex = connectorIdInt -1;
  12687. }
  12688. for (int index = 0; index < CCS_QUANTITY; index++)
  12689. {
  12690. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12691. {
  12692. //stop Transaction
  12693. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12694. }
  12695. }
  12696. }
  12697. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12698. {
  12699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12700. {
  12701. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12702. }
  12703. else
  12704. {
  12705. tempIndex = connectorIdInt -1;
  12706. }
  12707. for (int index = 0; index < GB_QUANTITY; index++)
  12708. {
  12709. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12710. {
  12711. //stop Transaction
  12712. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12713. }
  12714. }
  12715. }
  12716. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12717. {
  12718. tempIndex = connectorIdInt -1;
  12719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12720. {
  12721. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12722. {
  12723. //stop Transaction
  12724. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12725. }
  12726. }
  12727. }
  12728. else
  12729. {
  12730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12731. {
  12732. tempIndex = 2;
  12733. }
  12734. else
  12735. {
  12736. tempIndex = connectorIdInt-1;
  12737. }
  12738. for (int index = 0; index < AC_QUANTITY; index++)
  12739. {
  12740. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12741. {
  12742. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12743. }
  12744. }
  12745. }
  12746. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12747. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12748. result = TRUE;
  12749. return result;
  12750. }
  12751. end:
  12752. //json_object_put(obj); --- remove temporally
  12753. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12754. return result;
  12755. }
  12756. static char UpdateFirmwarepayloadData[300]={0};
  12757. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12758. {
  12759. mtrace();
  12760. int result = FAIL;
  12761. pthread_t t;
  12762. sendUpdateFirmwareConfirmation(uuid);
  12763. memset(UpdateFirmwarepayloadData, 0, 300);
  12764. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12765. if(!interLock.isUpdateFirmwareGoing)
  12766. {
  12767. interLock.isUpdateFirmwareGoing = 1;
  12768. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12769. sleep(1);
  12770. }
  12771. else
  12772. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12773. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12774. return result;
  12775. }
  12776. void *UpdateFirmwareProcess(void *data)
  12777. {
  12778. pthread_detach(pthread_self());
  12779. mtrace();
  12780. int retriesInt =0, retryIntervalInt=0;
  12781. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12782. int port=0;
  12783. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12784. int isSuccess = 0;
  12785. char ftpbuf[512];
  12786. char temp[100];
  12787. char * pch;
  12788. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12789. json_object *UpdateFirmware;
  12790. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12791. if(!is_error(UpdateFirmware))
  12792. {
  12793. // Required data
  12794. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12795. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12796. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12797. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12798. // Optional data
  12799. if(json_object_object_get(UpdateFirmware, "retries"))
  12800. {
  12801. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12802. }
  12803. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12804. {
  12805. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12806. }
  12807. }
  12808. json_object_put(UpdateFirmware);
  12809. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12810. memset(path, 0, ARRAY_SIZE(path));
  12811. // Wait retrieveData
  12812. if(strlen(retrieveDatestr) > 10)
  12813. {
  12814. do
  12815. {
  12816. sleep(1);
  12817. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12818. }
  12819. // Ready to download
  12820. system("rm -f /mnt/*");
  12821. if(strncmp(locationstr,"http", 4) == 0)
  12822. {
  12823. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12824. sprintf(ftppath,"/%s", path);
  12825. DEBUG_INFO("locationstr: %s\n", locationstr);
  12826. DEBUG_INFO("protocol: %s\n",protocol);
  12827. DEBUG_INFO("host: %s\n",host);
  12828. DEBUG_INFO("path: %s\n",path);
  12829. DEBUG_INFO("ftppath: %s\n",ftppath);
  12830. int ftppathlen=strlen(ftppath);
  12831. int i=1;
  12832. char filenametemp[50];
  12833. while(i < ftppathlen)
  12834. {
  12835. int len=ftppathlen-i;
  12836. if(ftppath[len]== 47) // '/' ascll code: 47
  12837. {
  12838. DEBUG_INFO("compare '/' all right\n");
  12839. break;
  12840. }
  12841. i=i+1;
  12842. }
  12843. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12844. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12845. filenametemp[i+1] = 0;
  12846. do
  12847. {
  12848. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12849. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12850. sleep(1);
  12851. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12852. if(!isSuccess)
  12853. {
  12854. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12855. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12856. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12857. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12858. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12859. }
  12860. else
  12861. {
  12862. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12863. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12864. }
  12865. retriesInt--;
  12866. }while((isSuccess == 0)&&(retriesInt >= 0));
  12867. }
  12868. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12869. {
  12870. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12871. memset(temp, 0, ARRAY_SIZE(temp));
  12872. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12873. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12874. int ftppathlen=strlen(ftpbuf);
  12875. int i=1;
  12876. char filenametemp[50];
  12877. while(i < ftppathlen)
  12878. {
  12879. int len=ftppathlen-i;
  12880. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12881. {
  12882. DEBUG_INFO(" compare '/' all right\n");
  12883. break;
  12884. }
  12885. i=i+1;
  12886. }
  12887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12888. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12889. filenametemp[i+1] = 0;
  12890. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12891. pch=strchr(temp,'@');
  12892. if(pch==NULL)
  12893. {
  12894. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12895. protocol, host, &port, path);
  12896. strcpy(user,"anonymous");
  12897. strcpy(password,"");
  12898. }
  12899. else
  12900. {
  12901. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12902. protocol, user, password, host, &port, path);
  12903. }
  12904. sscanf(host,"%[^/]%s",host1, path1);
  12905. sprintf(ftppath,"%s", path1);
  12906. //DEBUG_INFO("protocol =%s\n",protocol);
  12907. //DEBUG_INFO("user =%s\n",user);
  12908. //DEBUG_INFO("password =%s\n",password);
  12909. //DEBUG_INFO("host1 =%s\n",host1);
  12910. //DEBUG_INFO("port =%d\n",port);
  12911. //DEBUG_INFO("path1 =%s\n",path1);
  12912. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12913. //ftpFile(host, user, password, port, ftppath, fname);
  12914. //download firmware pthred
  12915. if(port == 0)
  12916. {
  12917. port = 21;
  12918. }
  12919. do
  12920. {
  12921. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12922. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12923. sleep(1);
  12924. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12925. if(!isSuccess)
  12926. {
  12927. //BulldogUtil.sleepMs(interval*1000);
  12928. DEBUG_INFO("Update firmware request and download file fail.\n");
  12929. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12930. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12931. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12932. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12933. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12934. }
  12935. else
  12936. {
  12937. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12938. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12939. }
  12940. retriesInt--;
  12941. }while((!isSuccess)&&(retriesInt >= 0));
  12942. }
  12943. else
  12944. {
  12945. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12946. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12947. sleep(1);
  12948. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12949. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12950. }
  12951. // OCPPPH only, must announce CSU upgrade firmware
  12952. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12953. interLock.isUpdateFirmwareGoing = 0;
  12954. pthread_exit(NULL);
  12955. }
  12956. int handleCertificateSignedRequest(char *uuid, char *payload)
  12957. {
  12958. mtrace();
  12959. int result = PASS;
  12960. json_object *CertificateSigned;
  12961. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12962. CertificateSigned = json_tokener_parse(payload);
  12963. if(!is_error(CertificateSigned))
  12964. {
  12965. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12966. }
  12967. json_object_put(CertificateSigned);
  12968. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12969. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12970. fclose(fp);
  12971. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12972. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12973. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12974. sendCertificateSignedConfirmation(uuid);
  12975. return result;
  12976. }
  12977. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12978. {
  12979. mtrace();
  12980. int result = PASS;
  12981. json_object *DeleteCertificate;
  12982. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12983. DeleteCertificate = json_tokener_parse(payload);
  12984. if(!is_error(DeleteCertificate))
  12985. {
  12986. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12987. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12988. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12989. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12990. }
  12991. json_object_put(DeleteCertificate);
  12992. /*
  12993. * TODO: Delete certificateSigned process
  12994. */
  12995. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12996. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12997. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12998. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12999. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13000. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13001. sendDeleteCertificateConfirmation(uuid);
  13002. return result;
  13003. }
  13004. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13005. {
  13006. mtrace();
  13007. int result = PASS;
  13008. json_object *ExtendedTriggerMessage;
  13009. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13010. ExtendedTriggerMessage = json_tokener_parse(payload);
  13011. if(!is_error(ExtendedTriggerMessage))
  13012. {
  13013. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13014. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13015. {
  13016. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13017. }
  13018. else
  13019. {
  13020. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13021. }
  13022. }
  13023. json_object_put(ExtendedTriggerMessage);
  13024. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13025. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13026. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13027. {
  13028. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13029. }
  13030. else
  13031. {
  13032. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13033. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13034. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13035. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13036. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13037. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13038. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13039. {
  13040. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13041. }
  13042. else
  13043. {
  13044. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13045. }
  13046. }
  13047. sendExtendedTriggerMessageConfirmation(uuid);
  13048. //==========================
  13049. // Trigger message
  13050. //==========================
  13051. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13052. {
  13053. //sendBootNotificationRequest();
  13054. server_sign = FALSE;
  13055. }
  13056. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13057. {
  13058. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13059. }
  13060. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13061. {
  13062. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13063. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13064. {
  13065. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13066. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13067. }
  13068. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13069. }
  13070. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13071. {
  13072. refreshStartTimer(&clientTime.Heartbeat);
  13073. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13074. }
  13075. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13076. {
  13077. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13078. {
  13079. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13080. }
  13081. else
  13082. {
  13083. for(int idx=0;idx< gunTotalNumber;idx++)
  13084. {
  13085. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13086. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13087. }
  13088. }
  13089. }
  13090. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13091. {
  13092. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13093. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13094. {
  13095. 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\" &");
  13096. }
  13097. }
  13098. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13099. {
  13100. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13101. {
  13102. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13103. }
  13104. else
  13105. {
  13106. for(int idx=0;idx< gunTotalNumber;idx++)
  13107. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13108. }
  13109. }
  13110. return result;
  13111. }
  13112. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13113. {
  13114. mtrace();
  13115. int result = PASS;
  13116. json_object *GetInstalledCertificateIds;
  13117. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13118. GetInstalledCertificateIds = json_tokener_parse(payload);
  13119. if(!is_error(GetInstalledCertificateIds))
  13120. {
  13121. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13122. }
  13123. json_object_put(GetInstalledCertificateIds);
  13124. /*
  13125. * TODO: Return installed certificate process
  13126. */
  13127. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13128. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13129. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13130. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13131. sendGetInstalledCertificateIdsConfirmation(uuid);
  13132. return result;
  13133. }
  13134. int handleGetLogRequest(char *uuid, char *payload)
  13135. {
  13136. mtrace();
  13137. int result = PASS;
  13138. json_object *GetLog;
  13139. DEBUG_INFO("handleGetLogRequest...\n");
  13140. GetLog = json_tokener_parse(payload);
  13141. if(!is_error(GetLog))
  13142. {
  13143. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13144. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13145. if(json_object_object_get(GetLog, "retries") != NULL)
  13146. {
  13147. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13148. }
  13149. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13150. {
  13151. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13152. }
  13153. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13154. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13155. {
  13156. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13157. }
  13158. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13159. {
  13160. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13161. }
  13162. }
  13163. json_object_put(GetLog);
  13164. /*
  13165. * TODO: Upload log process
  13166. */
  13167. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13168. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13169. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13170. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13171. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13172. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13173. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13174. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13175. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13176. sendGetLogConfirmation(uuid);
  13177. return result;
  13178. }
  13179. int handleInstallCertificateRequest(char *uuid, char *payload)
  13180. {
  13181. mtrace();
  13182. int result = PASS;
  13183. json_object *InstallCertificate;
  13184. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13185. InstallCertificate = json_tokener_parse(payload);
  13186. if(!is_error(InstallCertificate))
  13187. {
  13188. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13189. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13190. /*
  13191. * TODO: Install certificate process
  13192. */
  13193. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13194. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13195. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13196. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13197. sendInstallCertificateConfirmation(uuid);
  13198. }
  13199. json_object_put(InstallCertificate);
  13200. return result;
  13201. }
  13202. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13203. {
  13204. mtrace();
  13205. int result = PASS;
  13206. json_object *SignedUpdateFirmware;
  13207. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13208. SignedUpdateFirmware = json_tokener_parse(payload);
  13209. if(!is_error(SignedUpdateFirmware))
  13210. {
  13211. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13212. {
  13213. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13214. }
  13215. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13216. {
  13217. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13218. }
  13219. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13220. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13221. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13222. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13223. {
  13224. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13225. }
  13226. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13227. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13228. }
  13229. json_object_put(SignedUpdateFirmware);
  13230. /*
  13231. * TODO: Upgrade firmware process
  13232. */
  13233. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13234. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13235. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13236. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13237. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13238. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13239. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13240. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13241. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13242. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13243. sendInstallCertificateConfirmation(uuid);
  13244. return result;
  13245. }
  13246. int handleUnknownRequest(char *uuid, char *payload)
  13247. {
  13248. mtrace();
  13249. int result = PASS;
  13250. DEBUG_INFO("handleUnknownRequest...\n");
  13251. sendUnknownConfirmation(uuid);
  13252. result = PASS;
  13253. return result;
  13254. }
  13255. //==========================================
  13256. // Handle server response routine
  13257. //==========================================
  13258. void handleAuthorizeResponse(char *payload, int gun_index)
  13259. {
  13260. mtrace();
  13261. char expiryDatestr[36]={0};
  13262. char parentIdTagstr[21]={0};
  13263. char statusstr[20]={0};
  13264. int expiryDateISNULL=FALSE;
  13265. int parentIdTagISNULL=FALSE;
  13266. DEBUG_INFO("handleAuthorizeResponse...\n");
  13267. json_object *Authorize;
  13268. Authorize = json_tokener_parse(payload);
  13269. if(!is_error(Authorize))
  13270. {
  13271. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13272. {
  13273. // Required data
  13274. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13275. // Optional data
  13276. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13277. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13278. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13279. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13280. }
  13281. }
  13282. json_object_put(Authorize);
  13283. if(expiryDateISNULL == FALSE)
  13284. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13285. if(parentIdTagISNULL == FALSE)
  13286. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13287. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13288. //Update idTag information to authorization cache if supproted
  13289. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13290. {
  13291. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13292. }
  13293. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13294. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13295. authorizeRetryTimes = 0;
  13296. }
  13297. void handleBootNotificationResponse(char *payload, int gun_index)
  13298. {
  13299. mtrace();
  13300. char statusStr[12]={0};
  13301. char currentTimeStr[30]={0};
  13302. int intervalInt = 0;
  13303. DEBUG_INFO("handleBootNotificationResponse...\n");
  13304. json_object *BootNotification;
  13305. BootNotification = json_tokener_parse(payload);
  13306. if(!is_error(BootNotification))
  13307. {
  13308. // Required data
  13309. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13310. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13311. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13312. }
  13313. json_object_put(BootNotification);
  13314. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13315. BootNotificationInterval = intervalInt;
  13316. //write back to ShmOCPP16DataPH->BootNotification
  13317. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13318. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13319. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13320. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13321. {
  13322. BootNotificationInterval = 0;
  13323. if((intervalInt == 0) || (intervalInt >= 10))
  13324. {
  13325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13326. HeartBeatWaitTime = intervalInt;
  13327. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13328. }
  13329. server_sign = TRUE;
  13330. server_pending =FALSE;
  13331. }
  13332. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13333. {
  13334. server_pending = TRUE;
  13335. }
  13336. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13337. srand(time(NULL));
  13338. refreshStartTimer(&clientTime.Heartbeat);
  13339. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13340. SetOcppConnStatus(TRUE);
  13341. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13342. }
  13343. void handleDataTransferResponse(char *payload, int gun_index)
  13344. {
  13345. json_object *DataTransfer = json_tokener_parse(payload);
  13346. if(!is_error(DataTransfer))
  13347. {
  13348. // Required data
  13349. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13350. // Optional data
  13351. if(json_object_object_get(DataTransfer, "data") != NULL)
  13352. {
  13353. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13354. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13355. if(!is_error(Data))
  13356. {
  13357. if(json_object_object_get(Data, "msgId") != NULL)
  13358. {
  13359. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13360. {
  13361. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13362. }
  13363. }
  13364. }
  13365. json_object_put(Data);
  13366. }
  13367. }
  13368. json_object_put(DataTransfer);
  13369. }
  13370. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13371. {
  13372. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13373. //struct json_object *obj;
  13374. // obj = json_tokener_parse(payload);
  13375. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13376. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13377. //No fields are defined.
  13378. }
  13379. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13380. {
  13381. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13382. //struct json_object *obj;
  13383. // obj = json_tokener_parse(payload);
  13384. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13385. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13386. //No fields are defined.
  13387. }
  13388. void handleHeartbeatResponse(char *payload, int gun_index)
  13389. {
  13390. mtrace();
  13391. DEBUG_INFO("handleHeartbeatResponse...\n");
  13392. json_object *Heartbeat;
  13393. Heartbeat = json_tokener_parse(payload);
  13394. if(!is_error(Heartbeat))
  13395. {
  13396. // Required data
  13397. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13398. }
  13399. json_object_put(Heartbeat);
  13400. if(FirstHeartBeat == 0)
  13401. {
  13402. FirstHeartBeat = 1;
  13403. DEBUG_INFO("FirstHeartBeat \n");
  13404. }
  13405. HeartBeatWithNOResponse = 0;
  13406. refreshStartTimer(&clientTime.Heartbeat);
  13407. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13408. }
  13409. void handleMeterValuesResponse(char *payload, int gun_index)
  13410. {
  13411. mtrace();
  13412. DEBUG_INFO("handleMeterValuesResponse...\n");
  13413. isQueueSendable = 1;
  13414. }
  13415. void handleStartTransactionResponse(char *payload, int gun_index)
  13416. {
  13417. mtrace();
  13418. //int transactionIdInt = 0;
  13419. FILE *outfile;
  13420. char data[100]={0};
  13421. DEBUG_INFO("handleStartTransactionResponse...\n");
  13422. json_object *StartTransaction;
  13423. StartTransaction = json_tokener_parse(payload);
  13424. if(!is_error(StartTransaction))
  13425. {
  13426. // Required data
  13427. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13428. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13429. // Optional data
  13430. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13431. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13432. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13433. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13434. }
  13435. json_object_put(StartTransaction);
  13436. isQueueSendable = 1;
  13437. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13438. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13439. //-----------Start : write to the Queue TransactionId file -----------------//
  13440. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13441. {}
  13442. else
  13443. {
  13444. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13445. if(log == NULL)
  13446. {
  13447. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13448. return ;
  13449. }
  13450. else
  13451. {
  13452. fclose(log);
  13453. }
  13454. }
  13455. // open file for writing
  13456. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13457. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13458. {
  13459. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13460. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13461. fputs(data, outfile);
  13462. fclose (outfile);
  13463. }
  13464. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13465. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13466. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13467. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13468. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13469. }
  13470. void handleStatusNotificationResponse(char *payload, int gun_index)
  13471. {
  13472. mtrace();
  13473. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13474. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13475. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13476. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13477. }
  13478. void handleStopTransactionnResponse(char *payload, int gun_index)
  13479. {
  13480. mtrace();
  13481. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13482. json_object *StopTransaction;
  13483. StopTransaction = json_tokener_parse(payload);
  13484. if(!is_error(StopTransaction))
  13485. {
  13486. // Optional data
  13487. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13488. {
  13489. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13490. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13491. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13492. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13493. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13494. }
  13495. }
  13496. json_object_put(StopTransaction);
  13497. isQueueSendable = 1;
  13498. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13499. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13500. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13501. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13502. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13503. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13504. }
  13505. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13506. {
  13507. mtrace();
  13508. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13509. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13510. }
  13511. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13512. {
  13513. mtrace();
  13514. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13515. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13516. }
  13517. void handleSignCertificateResponse(char *payload, int gun_index)
  13518. {
  13519. mtrace();
  13520. DEBUG_INFO("handleSignCertificateResponse...\n");
  13521. json_object *SignCertificate;
  13522. SignCertificate = json_tokener_parse(payload);
  13523. if(!is_error(SignCertificate))
  13524. {
  13525. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13526. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13527. }
  13528. json_object_put(SignCertificate);
  13529. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13530. }
  13531. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13532. {
  13533. mtrace();
  13534. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13535. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13536. }
  13537. //==========================================
  13538. // Handle Error routine
  13539. //==========================================
  13540. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13541. {
  13542. mtrace();
  13543. #ifdef SystemLogMessage
  13544. DEBUG_INFO("errorCode: %s\n", errorCode);
  13545. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13546. DEBUG_INFO("errorDetails: %s\n", payload);
  13547. #endif
  13548. }
  13549. //===============================================
  13550. // Common routine
  13551. //===============================================
  13552. int initialConfigurationTable(void)
  13553. {
  13554. //clock_t start_t, end_t, total_t;
  13555. FILE *fp;
  13556. FILE *outfile;
  13557. char str[512]={0};
  13558. char sstr[256]={0};
  13559. int c = 0;
  13560. char *loc;
  13561. int confVersion = 14;
  13562. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13563. //start_t = clock();
  13564. //printf("Starting of the program, start_t = %ld\n", start_t);
  13565. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13566. // Check configuration file size is correct
  13567. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13568. {
  13569. struct stat st;
  13570. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13571. if(st.st_size < 3100)
  13572. {
  13573. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13574. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13575. }
  13576. }
  13577. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13578. {
  13579. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13580. if(outfile == NULL)
  13581. {
  13582. DEBUG_INFO("Error opening file\n");
  13583. return FALSE;
  13584. }
  13585. /*Core Profile*/
  13586. //AllowOfflineTxForUnknownId
  13587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13591. //AuthorizationCacheEnabled
  13592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13596. //AuthorizeRemoteTxRequests
  13597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13601. //BlinkRepeat
  13602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13606. //ClockAlignedDataInterval
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13611. //ConnectionTimeOut
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13616. //GetConfigurationMaxKeys
  13617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13621. // HeartbeatInterval
  13622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13626. // LightIntensity
  13627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13631. // LocalAuthorizeOffline
  13632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13636. // LocalPreAuthorize
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13641. // MaxEnergyOnInvalidId
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13646. // MeterValuesAlignedData
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13650. 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" );
  13651. else
  13652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13654. // MeterValuesAlignedDataMaxLength
  13655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13659. else
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13662. // MeterValuesSampledData
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13666. 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" );
  13667. else
  13668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13670. // MeterValuesSampledDataMaxLength
  13671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13675. else
  13676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13678. // MeterValueSampleInterval
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13683. // MinimumStatusDuration
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13687. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13689. // NumberOfConnectors
  13690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13693. {
  13694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13695. }
  13696. else
  13697. {
  13698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13699. }
  13700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13701. // ResetRetries
  13702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13706. // ConnectorPhaseRotation
  13707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13711. // ConnectorPhaseRotationMaxLength
  13712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13716. // StopTransactionOnEVSideDisconnect
  13717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13721. // StopTransactionOnInvalidId
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13726. // StopTxnAlignedData
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13731. // StopTxnAlignedDataMaxLength
  13732. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13736. // StopTxnSampledData
  13737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13741. else
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13744. // StopTxnSampledDataMaxLength
  13745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13748. {
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13750. }
  13751. else
  13752. {
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13754. }
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13756. // SupportedFeatureProfiles
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13761. // SupportedFeatureProfilesMaxLength
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13766. // TransactionMessageAttempts
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13770. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13772. // TransactionMessageRetryInterval
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13776. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13778. // UnlockConnectorOnEVSideDisconnect
  13779. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13783. // WebSocketPingInterval
  13784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13788. // QueueOffLineMeterValues
  13789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13793. // AuthorizationKey
  13794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13798. // SecurityProfile
  13799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13801. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13803. // DefaultPrice
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13808. // CustomDisplayCostAndPrice
  13809. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13813. // CustomIdleFeeAfterStop
  13814. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13818. // SystemUptimeSec
  13819. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13823. // FreeVend
  13824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13828. // FreeVendIdtag
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13833. // OcppServer
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13836. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13838. // MaintainServer
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13841. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13843. // StatusNotificationPeriodically
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13848. // StatusNotificationInterval
  13849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13853. // isEnableLocalPowerSharing
  13854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13858. // PowerSharingServerIP
  13859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13861. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13863. // EVCCID_PREFIX
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13868. // Configuration Version
  13869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13873. //* Local Auth List Management Profile*/
  13874. #if 0
  13875. //For OCTT Test Case
  13876. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13879. #endif
  13880. #if 1
  13881. //LocalAuthListEnabled
  13882. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13886. #endif
  13887. //LocalAuthListMaxLength
  13888. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13892. //SendLocalListMaxLength
  13893. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13897. //ReserveConnectorZeroSupported
  13898. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13902. //* Smart Charging Profile */
  13903. //ChargeProfileMaxStackLevel
  13904. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13908. // ChargingScheduleAllowedChargingRateUnit
  13909. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13913. // ChargingScheduleMaxPeriods
  13914. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13918. // ConnectorSwitch3to1PhaseSupported
  13919. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13923. // MaxChargingProfilesInstalled
  13924. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13928. fclose(outfile);
  13929. }
  13930. else
  13931. {
  13932. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13933. char keystr[60]={0};
  13934. char readonlystr[10]={0};
  13935. char valuestr[256]={0};
  13936. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13937. if(fp == NULL) {
  13938. DEBUG_INFO("Error opening file");
  13939. return FALSE;
  13940. }
  13941. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13942. {
  13943. //DEBUG_INFO("Get Configuration \n");
  13944. if(strlen(str) > 0)
  13945. {
  13946. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13947. //*************************key*********************************/
  13948. if(strstr(str, "key") != NULL)
  13949. {
  13950. loc = strstr(str, "key");
  13951. c = 0;
  13952. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13953. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13954. {
  13955. sstr[c] = loc[strlen("key")+3+c];
  13956. c++;
  13957. }
  13958. sstr[c] = '\0';
  13959. strcpy(keystr,sstr);
  13960. }
  13961. //*************************readonly*********************************/
  13962. if(strstr(str, "readonly") != NULL)
  13963. {
  13964. loc = strstr(str, "readonly");
  13965. c = 0;
  13966. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13967. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13968. {
  13969. sstr[c] = loc[strlen("readonly")+2+c];
  13970. c++;
  13971. }
  13972. sstr[c] = '\0';
  13973. strcpy(readonlystr,sstr);
  13974. }
  13975. //*************************value*********************************/
  13976. if(strstr(str, "value") != NULL)
  13977. {
  13978. loc = strstr(str, "value");
  13979. c = 0;
  13980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13981. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13982. {
  13983. sstr[c] = loc[strlen("value")+3+c];
  13984. c++;
  13985. }
  13986. sstr[c] = '\0';
  13987. strcpy(valuestr,sstr);
  13988. }
  13989. // DEBUG_INFO("keystr=%s\n",keystr);
  13990. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13991. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13992. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13993. {
  13994. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13995. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13997. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13998. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13999. }
  14000. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14001. {
  14002. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14004. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14005. }
  14006. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14007. {
  14008. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14009. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14010. }
  14011. if(strcmp(keystr, "BlinkRepeat") == 0)
  14012. {
  14013. //Charger.BlinkRepeat = Integer.parseInt(value);
  14014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14016. }
  14017. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14018. {
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14021. }
  14022. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14023. {
  14024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14026. }
  14027. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14028. {
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14031. }
  14032. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14033. {
  14034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14035. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14036. HeartBeatWaitTime = atoi(valuestr);
  14037. }
  14038. if(strcmp(keystr, "LightIntensity") == 0)
  14039. {
  14040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14042. }
  14043. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14044. {
  14045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14047. }
  14048. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14049. {
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14051. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14052. }
  14053. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14054. {
  14055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14056. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14057. }
  14058. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14059. {
  14060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14062. }
  14063. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14064. {
  14065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14066. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14067. }
  14068. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14069. {
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14072. }
  14073. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14074. {
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14076. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14077. }
  14078. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14079. {
  14080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14082. }
  14083. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14084. {
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14087. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14088. }
  14089. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14090. {
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14092. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14093. }
  14094. if(strcmp(keystr, "ResetRetries") == 0)
  14095. {
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14098. }
  14099. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14100. {
  14101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14102. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14103. }
  14104. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14105. {
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14107. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14108. }
  14109. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14110. {
  14111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14112. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14113. }
  14114. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14115. {
  14116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14118. }
  14119. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14120. {
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14123. }
  14124. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14125. {
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14128. }
  14129. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14130. {
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14133. }
  14134. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14135. {
  14136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14138. }
  14139. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14140. {
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14143. }
  14144. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14145. {
  14146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14148. }
  14149. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14150. {
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14153. TransactionMessageAttemptsValue = atoi(valuestr);
  14154. }
  14155. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14156. {
  14157. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14159. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14160. }
  14161. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14162. {
  14163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14164. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14165. }
  14166. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14167. {
  14168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14170. }
  14171. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14172. {
  14173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14174. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14175. }
  14176. if(strcmp(keystr, "AuthorizationKey") == 0)
  14177. {
  14178. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14179. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14181. }
  14182. if(strcmp(keystr, "SecurityProfile") == 0)
  14183. {
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14185. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14186. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14187. }
  14188. if(strcmp(keystr, "DefaultPrice") == 0)
  14189. {
  14190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14191. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14192. }
  14193. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14194. {
  14195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14196. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14197. }
  14198. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14199. {
  14200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14201. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14202. }
  14203. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14204. {
  14205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14206. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14207. }
  14208. if(strcmp(keystr, "FreeVend") == 0)
  14209. {
  14210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14212. }
  14213. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14214. {
  14215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14216. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14217. }
  14218. if(strcmp(keystr, "OcppServer") == 0)
  14219. {
  14220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14221. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14222. }
  14223. if(strcmp(keystr, "MaintainServer") == 0)
  14224. {
  14225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14226. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14227. }
  14228. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14229. {
  14230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14232. }
  14233. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14234. {
  14235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14236. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14237. }
  14238. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14239. {
  14240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14242. }
  14243. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14244. {
  14245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14247. }
  14248. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14249. {
  14250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14252. }
  14253. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14254. {
  14255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14257. }
  14258. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14259. {
  14260. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14262. }
  14263. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14264. {
  14265. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14267. }
  14268. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14269. {
  14270. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14272. }
  14273. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14274. {
  14275. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14277. }
  14278. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14279. {
  14280. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14282. }
  14283. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14284. {
  14285. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14287. }
  14288. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14289. {
  14290. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14292. }
  14293. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14294. {
  14295. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14296. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14297. }
  14298. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14299. {
  14300. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14302. }
  14303. }
  14304. }
  14305. fclose(fp);
  14306. }
  14307. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14308. {
  14309. return PASS;
  14310. }
  14311. else
  14312. {
  14313. return FAIL;
  14314. }
  14315. }
  14316. void StoreConfigurationTable(void)
  14317. {
  14318. FILE *outfile;
  14319. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14320. if(outfile == NULL)
  14321. {
  14322. DEBUG_INFO("Error opening file");
  14323. return ;
  14324. }
  14325. /*Core Profile*/
  14326. //AllowOfflineTxForUnknownId
  14327. /*
  14328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14329. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14332. */
  14333. //DEBUG_INFO("data=%s\n",data);
  14334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14335. //AuthorizationCacheEnabled
  14336. /*
  14337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14340. */
  14341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14342. //AuthorizeRemoteTxRequests
  14343. /*
  14344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14347. */
  14348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14349. //BlinkRepeat
  14350. /*
  14351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14354. */
  14355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14356. //ClockAlignedDataInterval
  14357. /*
  14358. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14359. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14361. */
  14362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14363. //ConnectionTimeOut
  14364. /*
  14365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14368. */
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14370. //GetConfigurationMaxKeys
  14371. /*
  14372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14375. */
  14376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14377. // HeartbeatInterval
  14378. /*
  14379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14382. */
  14383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14384. // LightIntensity
  14385. /*
  14386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14389. */
  14390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14391. // LocalAuthorizeOffline
  14392. /*
  14393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14396. */
  14397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14398. // LocalPreAuthorize
  14399. /*
  14400. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14403. */
  14404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14405. // MaxEnergyOnInvalidId
  14406. /*
  14407. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14410. */
  14411. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14413. // MeterValuesAlignedData
  14414. /*
  14415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14418. */
  14419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14420. // MeterValuesAlignedDataMaxLength
  14421. /*
  14422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14425. */
  14426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14427. // MeterValuesSampledData
  14428. /*
  14429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14432. */
  14433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14434. // MeterValuesSampledDataMaxLength
  14435. /*
  14436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14439. */
  14440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14441. // MeterValueSampleInterval
  14442. /*
  14443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14444. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14446. */
  14447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14448. // MinimumStatusDuration
  14449. /*
  14450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14453. */
  14454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14455. // NumberOfConnectors
  14456. /*
  14457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14460. {
  14461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14462. }
  14463. else
  14464. {
  14465. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14466. }
  14467. */
  14468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14469. // ResetRetries
  14470. /*
  14471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14474. */
  14475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14476. // ConnectorPhaseRotation
  14477. /*
  14478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14481. */
  14482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14483. // ConnectorPhaseRotationMaxLength
  14484. /*
  14485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14486. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14488. */
  14489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14490. // StopTransactionOnEVSideDisconnect
  14491. /*
  14492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14495. */
  14496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14497. // StopTransactionOnInvalidId
  14498. /*
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14502. */
  14503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14504. // StopTxnAlignedData
  14505. /*
  14506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14509. */
  14510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14511. // StopTxnAlignedDataMaxLength
  14512. /*
  14513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14515. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14516. */
  14517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14518. // StopTxnSampledData
  14519. /*
  14520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14521. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14523. */
  14524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14525. // StopTxnSampledDataMaxLength
  14526. /*
  14527. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14530. */
  14531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14532. // SupportedFeatureProfiles
  14533. /*
  14534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14535. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14537. */
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14539. // SupportedFeatureProfilesMaxLength
  14540. /*
  14541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14544. */
  14545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14546. // TransactionMessageAttempts
  14547. /*
  14548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14551. */
  14552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14553. // TransactionMessageRetryInterval
  14554. /*
  14555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14558. */
  14559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14560. // UnlockConnectorOnEVSideDisconnect
  14561. /*
  14562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14565. */
  14566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14567. // WebSocketPingInterval
  14568. /*
  14569. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14572. */
  14573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14574. // QueueOffLineMeterValues
  14575. /*
  14576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14579. */
  14580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14581. // AuthorizationKey
  14582. /*
  14583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14586. */
  14587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14588. // SecurityProfile
  14589. /*
  14590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14593. */
  14594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14595. // DefaultPrice
  14596. /*
  14597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14600. */
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14602. // CustomDisplayCostAndPrice
  14603. /*
  14604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14607. */
  14608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14609. // CustomIdleFeeAfterStop
  14610. /*
  14611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14614. */
  14615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14616. // SystemUptimeSec
  14617. /*
  14618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14621. */
  14622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14623. // FreeVend
  14624. /*
  14625. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14626. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14628. */
  14629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14630. // FreeVendIdtag
  14631. /*
  14632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14635. */
  14636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14637. // OcppServer
  14638. /*
  14639. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14642. */
  14643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14644. // MaintainServer
  14645. /*
  14646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14649. */
  14650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14651. // StatusNotificationPeriodically
  14652. /*
  14653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14656. */
  14657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14658. // StatusNotificationInterval
  14659. /*
  14660. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14663. */
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14665. // isEnableLocalPowerSharing
  14666. /*
  14667. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14670. */
  14671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14672. // PowerSharingServerIP
  14673. /*
  14674. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14677. */
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14679. // EVCCID_PREFIX
  14680. /*
  14681. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14684. */
  14685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14686. // ConfigurationVersion
  14687. /*
  14688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14691. */
  14692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14693. //* Local Auth List Management Profile*/
  14694. //LocalAuthListEnabled
  14695. /*
  14696. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14699. */
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14701. //LocalAuthListMaxLength
  14702. /*
  14703. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14706. */
  14707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14708. //SendLocalListMaxLength
  14709. /*
  14710. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14713. */
  14714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14715. //ReserveConnectorZeroSupported
  14716. /*
  14717. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14720. */
  14721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14722. //* Smart Charging Profile */
  14723. //ChargeProfileMaxStackLevel
  14724. /*
  14725. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14728. */
  14729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14730. // ChargingScheduleAllowedChargingRateUnit
  14731. /*
  14732. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14735. */
  14736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14737. // ChargingScheduleMaxPeriods
  14738. /*
  14739. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14742. */
  14743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14744. // ConnectorSwitch3to1PhaseSupported
  14745. /*
  14746. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14749. */
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14751. // MaxChargingProfilesInstalled
  14752. /*
  14753. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14756. */
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14758. fclose(outfile);
  14759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14760. }
  14761. void getKeyValue(char *keyReq)
  14762. {
  14763. int isEmpty = FALSE;
  14764. int isKnowKey = FALSE;
  14765. DEBUG_INFO("keyReq = %s\n", keyReq);
  14766. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14767. isEmpty = TRUE;
  14768. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14769. {
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14772. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14773. {
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14775. }
  14776. else
  14777. {
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14779. }
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14781. isKnowKey = TRUE;
  14782. }
  14783. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14784. {
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14787. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14788. {
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14790. }
  14791. else
  14792. {
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14794. }
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14796. isKnowKey = TRUE;
  14797. }
  14798. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14799. {
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14802. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14803. {
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14805. }
  14806. else
  14807. {
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14809. }
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14811. isKnowKey = TRUE;
  14812. }
  14813. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14814. {
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14817. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14818. {
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14820. }
  14821. else
  14822. {
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14824. }
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14826. isKnowKey = TRUE;
  14827. }
  14828. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14829. {
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14832. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14833. {
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14835. }
  14836. else
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14839. }
  14840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14841. isKnowKey = TRUE;
  14842. }
  14843. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14844. {
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14847. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14848. {
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14850. }
  14851. else
  14852. {
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14854. }
  14855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14856. isKnowKey = TRUE;
  14857. }
  14858. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14859. {
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14862. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14865. }
  14866. else
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14869. }
  14870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14871. isKnowKey = TRUE;
  14872. }
  14873. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14874. {
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14877. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14878. {
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14880. }
  14881. else
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14884. }
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14886. isKnowKey = TRUE;
  14887. }
  14888. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14889. {
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14892. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14893. {
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14895. }
  14896. else
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14899. }
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14901. isKnowKey = TRUE;
  14902. }
  14903. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14904. {
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14908. {
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14910. }
  14911. else
  14912. {
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14914. }
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14916. isKnowKey = TRUE;
  14917. }
  14918. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14919. {
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14922. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14923. {
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14925. }
  14926. else
  14927. {
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14929. }
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14931. isKnowKey = TRUE;
  14932. }
  14933. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14934. {
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14937. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14938. {
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14940. }
  14941. else
  14942. {
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14944. }
  14945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14946. isKnowKey = TRUE;
  14947. }
  14948. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14949. {
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14952. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14953. {
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14955. }
  14956. else
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14959. }
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14961. isKnowKey = TRUE;
  14962. }
  14963. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14964. {
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14967. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14968. {
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14970. }
  14971. else
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14974. }
  14975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14976. isKnowKey = TRUE;
  14977. }
  14978. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14979. {
  14980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14982. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14983. {
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14985. }
  14986. else
  14987. {
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14989. }
  14990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14991. isKnowKey = TRUE;
  14992. }
  14993. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14994. {
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14997. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14998. {
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15000. }
  15001. else
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15004. }
  15005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15006. isKnowKey = TRUE;
  15007. }
  15008. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15009. {
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15012. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15015. }
  15016. else
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15019. }
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15021. isKnowKey = TRUE;
  15022. }
  15023. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15024. {
  15025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15027. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15028. {
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15030. }
  15031. else
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15034. }
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15036. isKnowKey = TRUE;
  15037. }
  15038. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15039. {
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15042. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15045. }
  15046. else
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15049. }
  15050. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15052. isKnowKey = TRUE;
  15053. }
  15054. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15058. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15073. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15082. isKnowKey = TRUE;
  15083. }
  15084. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15085. {
  15086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15091. }
  15092. else
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15095. }
  15096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15097. isKnowKey = TRUE;
  15098. }
  15099. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15100. {
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15103. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15106. }
  15107. else
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15110. }
  15111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15112. isKnowKey = TRUE;
  15113. }
  15114. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15115. {
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15118. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15121. }
  15122. else
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15125. }
  15126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15127. isKnowKey = TRUE;
  15128. }
  15129. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15130. {
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15133. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15136. }
  15137. else
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15140. }
  15141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15142. isKnowKey = TRUE;
  15143. }
  15144. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15145. {
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15151. }
  15152. else
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15155. }
  15156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15157. isKnowKey = TRUE;
  15158. }
  15159. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15160. {
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15166. }
  15167. else
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15170. }
  15171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15172. isKnowKey = TRUE;
  15173. }
  15174. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15175. {
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15179. {
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15181. }
  15182. else
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15185. }
  15186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15187. isKnowKey = TRUE;
  15188. }
  15189. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15190. {
  15191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15193. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15194. {
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15196. }
  15197. else
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15200. }
  15201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15202. isKnowKey = TRUE;
  15203. }
  15204. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15205. {
  15206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15208. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15209. {
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15211. }
  15212. else
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15215. }
  15216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15217. isKnowKey = TRUE;
  15218. }
  15219. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15220. {
  15221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15223. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15224. {
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15226. }
  15227. else
  15228. {
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15230. }
  15231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15232. isKnowKey = TRUE;
  15233. }
  15234. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15235. {
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15238. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15253. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15262. isKnowKey = TRUE;
  15263. }
  15264. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15268. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15292. isKnowKey = TRUE;
  15293. }
  15294. /*
  15295. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15296. {
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15299. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15302. }
  15303. else
  15304. {
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15306. }
  15307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15308. isKnowKey = TRUE;
  15309. }*/
  15310. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15311. {
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15314. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15317. }
  15318. else
  15319. {
  15320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15321. }
  15322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15323. isKnowKey = TRUE;
  15324. }
  15325. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15326. {
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15329. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15332. }
  15333. else
  15334. {
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15336. }
  15337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15338. isKnowKey = TRUE;
  15339. }
  15340. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15341. {
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15351. }
  15352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15353. isKnowKey = TRUE;
  15354. }
  15355. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15356. {
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15362. }
  15363. else
  15364. {
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15366. }
  15367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15368. isKnowKey = TRUE;
  15369. }
  15370. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15371. {
  15372. struct sysinfo s_info;
  15373. int error = sysinfo(&s_info);
  15374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15377. {
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15379. }
  15380. else
  15381. {
  15382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15383. }
  15384. if(error != 0)
  15385. {
  15386. DEBUG_WARN("System uptime get error: %d\n", error);
  15387. }
  15388. else
  15389. {
  15390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15391. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15392. }
  15393. isKnowKey = TRUE;
  15394. }
  15395. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15396. {
  15397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15399. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15400. {
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15402. }
  15403. else
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15406. }
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15408. isKnowKey = TRUE;
  15409. }
  15410. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15411. {
  15412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15415. {
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15417. }
  15418. else
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15421. }
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15423. isKnowKey = TRUE;
  15424. }
  15425. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15426. {
  15427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15430. {
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15432. }
  15433. else
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15436. }
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15438. isKnowKey = TRUE;
  15439. }
  15440. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15441. {
  15442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15445. {
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15447. }
  15448. else
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15451. }
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15453. isKnowKey = TRUE;
  15454. }
  15455. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15456. {
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15460. {
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15462. }
  15463. else
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15466. }
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15468. isKnowKey = TRUE;
  15469. }
  15470. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15471. {
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15475. {
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15477. }
  15478. else
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15481. }
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15483. isKnowKey = TRUE;
  15484. }
  15485. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15486. {
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15490. {
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15492. }
  15493. else
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15496. }
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15498. isKnowKey = TRUE;
  15499. }
  15500. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15501. {
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15505. {
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15507. }
  15508. else
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15511. }
  15512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15513. isKnowKey = TRUE;
  15514. }
  15515. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15516. {
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15520. {
  15521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15522. }
  15523. else
  15524. {
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15526. }
  15527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15528. isKnowKey = TRUE;
  15529. }
  15530. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15531. {
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15534. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15535. {
  15536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15537. }
  15538. else
  15539. {
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15541. }
  15542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15543. isKnowKey = TRUE;
  15544. }
  15545. #if 1
  15546. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15547. {
  15548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15550. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15557. }
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15559. isKnowKey = TRUE;
  15560. }
  15561. #endif
  15562. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15563. {
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15566. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15567. {
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15569. }
  15570. else
  15571. {
  15572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15573. }
  15574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15575. isKnowKey = TRUE;
  15576. }
  15577. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15578. {
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15581. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15582. {
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15584. }
  15585. else
  15586. {
  15587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15588. }
  15589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15590. isKnowKey = TRUE;
  15591. }
  15592. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15593. {
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15596. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15597. {
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15599. }
  15600. else
  15601. {
  15602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15603. }
  15604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15605. isKnowKey = TRUE;
  15606. }
  15607. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15608. {
  15609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15611. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15612. {
  15613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15614. }
  15615. else
  15616. {
  15617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15618. }
  15619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15620. isKnowKey = TRUE;
  15621. }
  15622. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15623. {
  15624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15626. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15627. {
  15628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15629. }
  15630. else
  15631. {
  15632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15633. }
  15634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15635. isKnowKey = TRUE;
  15636. }
  15637. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15638. {
  15639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15641. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15642. {
  15643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15644. }
  15645. else
  15646. {
  15647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15648. }
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15650. isKnowKey = TRUE;
  15651. }
  15652. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15653. {
  15654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15656. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15657. {
  15658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15659. }
  15660. else
  15661. {
  15662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15663. }
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15665. isKnowKey = TRUE;
  15666. }
  15667. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15668. {
  15669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15671. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15672. {
  15673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15674. }
  15675. else
  15676. {
  15677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15678. }
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15680. isKnowKey = TRUE;
  15681. }
  15682. //=========================================================
  15683. if(!isEmpty && !isKnowKey)
  15684. {
  15685. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15686. strcpy(unknownkey[UnknownKeynum], keyReq);
  15687. UnknownKeynum = UnknownKeynum + 1;
  15688. }
  15689. }
  15690. void processUnkownKey(void)
  15691. {
  15692. DEBUG_INFO("processUnkownKey...\n");
  15693. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15694. for(int index=0; index < UnknownKeynum; index++)
  15695. {
  15696. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15697. {
  15698. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15699. }
  15700. }
  15701. }
  15702. int setKeyValue(char *key, char *value)
  15703. {
  15704. int isSuccess = NotSupported;
  15705. int check_ascii=0;
  15706. char str[501]={0};
  15707. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15708. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15709. {
  15710. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15712. {
  15713. strcpy(str, (const char*)value);
  15714. for(int i = 0; str[i]; i++){
  15715. str[i] = tolower(str[i]);
  15716. }
  15717. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15718. isSuccess = ConfigurationStatus_Accepted;
  15719. }
  15720. else
  15721. {
  15722. isSuccess = ConfigurationStatus_Rejected;
  15723. }
  15724. }
  15725. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15726. {
  15727. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15729. {
  15730. strcpy(str, (const char*)value);
  15731. for(int i = 0; str[i]; i++){
  15732. str[i] = tolower(str[i]);
  15733. }
  15734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15735. isSuccess = ConfigurationStatus_Accepted;
  15736. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15737. }
  15738. else
  15739. {
  15740. isSuccess = ConfigurationStatus_Rejected;
  15741. }
  15742. }
  15743. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15744. {
  15745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15746. {
  15747. strcpy(str, (const char*)value);
  15748. for(int i = 0; str[i]; i++)
  15749. {
  15750. str[i] = tolower(str[i]);
  15751. }
  15752. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15754. isSuccess = ConfigurationStatus_Accepted;
  15755. }
  15756. else
  15757. {
  15758. isSuccess = ConfigurationStatus_Rejected;
  15759. }
  15760. }
  15761. if(strcmp(key, "BlinkRepeat") == 0)
  15762. {
  15763. //Charger.BlinkRepeat = Integer.parseInt(value);
  15764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15765. {
  15766. check_ascii = value[0];
  15767. if( (check_ascii < 48) || (check_ascii > 57) )
  15768. {
  15769. isSuccess = ConfigurationStatus_Rejected;
  15770. }
  15771. else
  15772. {
  15773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15774. isSuccess = ConfigurationStatus_Accepted;
  15775. }
  15776. }
  15777. else
  15778. {
  15779. isSuccess = ConfigurationStatus_Rejected;
  15780. }
  15781. }
  15782. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15783. {
  15784. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15785. {
  15786. check_ascii = value[0];
  15787. if( (check_ascii < 48) || (check_ascii > 57) )
  15788. {
  15789. isSuccess = ConfigurationStatus_Rejected;
  15790. }
  15791. else
  15792. {
  15793. if((atoi(value) == 0) || (atoi(value) >= 5))
  15794. {
  15795. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15796. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15797. isSuccess = ConfigurationStatus_Accepted;
  15798. }
  15799. else
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. }
  15803. else
  15804. {
  15805. isSuccess = ConfigurationStatus_Rejected;
  15806. }
  15807. }
  15808. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15809. {
  15810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15811. {
  15812. check_ascii = value[0];
  15813. if( (check_ascii < 48) || (check_ascii > 57) )
  15814. {
  15815. isSuccess = ConfigurationStatus_Rejected;
  15816. }
  15817. else
  15818. {
  15819. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15821. isSuccess = ConfigurationStatus_Accepted;
  15822. }
  15823. }
  15824. else
  15825. {
  15826. isSuccess = ConfigurationStatus_Rejected;
  15827. }
  15828. }
  15829. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15830. {
  15831. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15832. {
  15833. check_ascii = value[0];
  15834. if( (check_ascii < 48) || (check_ascii > 57) )
  15835. {
  15836. isSuccess = ConfigurationStatus_Rejected;
  15837. }
  15838. else
  15839. {
  15840. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15842. isSuccess = ConfigurationStatus_Accepted;
  15843. }
  15844. }
  15845. else
  15846. {
  15847. isSuccess = ConfigurationStatus_Rejected;
  15848. }
  15849. }
  15850. if(strcmp(key, "HeartbeatInterval") == 0)
  15851. {
  15852. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15853. {
  15854. check_ascii = value[0];
  15855. if( (check_ascii < 48) || (check_ascii > 57) )
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. else
  15860. {
  15861. if((atoi(value) == 0) || (atoi(value) >= 10))
  15862. {
  15863. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15864. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15865. HeartBeatWaitTime = atoi(value);
  15866. isSuccess = ConfigurationStatus_Accepted;
  15867. }
  15868. else
  15869. {
  15870. isSuccess = ConfigurationStatus_Rejected;
  15871. }
  15872. }
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "LightIntensity") == 0)
  15880. {
  15881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15882. {
  15883. check_ascii = value[0];
  15884. if( (check_ascii < 48) || (check_ascii > 57) )
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. else
  15889. {
  15890. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15891. isSuccess = ConfigurationStatus_Accepted;
  15892. }
  15893. }
  15894. else
  15895. {
  15896. isSuccess = ConfigurationStatus_Rejected;
  15897. }
  15898. }
  15899. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15900. {
  15901. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15902. {
  15903. strcpy(str, (const char*)value);
  15904. for(int i = 0; str[i]; i++)
  15905. {
  15906. str[i] = tolower(str[i]);
  15907. }
  15908. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15909. isSuccess = ConfigurationStatus_Accepted;
  15910. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15911. }
  15912. else
  15913. {
  15914. isSuccess = ConfigurationStatus_Rejected;
  15915. }
  15916. }
  15917. if(strcmp(key, "LocalPreAuthorize") == 0)
  15918. {
  15919. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15920. {
  15921. strcpy(str, (const char*)value);
  15922. for(int i = 0; str[i]; i++)
  15923. {
  15924. str[i] = tolower(str[i]);
  15925. }
  15926. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15927. isSuccess = ConfigurationStatus_Accepted;
  15928. }
  15929. else
  15930. {
  15931. isSuccess = ConfigurationStatus_Rejected;
  15932. }
  15933. }
  15934. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15935. {
  15936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15937. {
  15938. check_ascii = value[0];
  15939. if( (check_ascii < 48) || (check_ascii > 57) )
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. else
  15944. {
  15945. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15946. isSuccess = ConfigurationStatus_Accepted;
  15947. }
  15948. }
  15949. else
  15950. {
  15951. isSuccess = ConfigurationStatus_Rejected;
  15952. }
  15953. }
  15954. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15955. {
  15956. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15957. {
  15958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15959. isSuccess = ConfigurationStatus_Accepted;
  15960. }
  15961. else
  15962. {
  15963. isSuccess = ConfigurationStatus_Rejected;
  15964. }
  15965. }
  15966. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15967. {
  15968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15969. {
  15970. check_ascii = value[0];
  15971. if( (check_ascii < 48) || (check_ascii > 57) )
  15972. {
  15973. isSuccess = ConfigurationStatus_Rejected;
  15974. }
  15975. else
  15976. {
  15977. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15979. isSuccess = ConfigurationStatus_Accepted;
  15980. }
  15981. }
  15982. else
  15983. {
  15984. isSuccess = ConfigurationStatus_Rejected;
  15985. }
  15986. }
  15987. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15988. {
  15989. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15990. {
  15991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15992. isSuccess = ConfigurationStatus_Accepted;
  15993. }
  15994. else
  15995. {
  15996. isSuccess = ConfigurationStatus_Rejected;
  15997. }
  15998. }
  15999. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16000. {
  16001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16002. {
  16003. check_ascii = value[0];
  16004. if( (check_ascii < 48) || (check_ascii > 57) )
  16005. {
  16006. isSuccess = ConfigurationStatus_Rejected;
  16007. }
  16008. else
  16009. {
  16010. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. }
  16015. else
  16016. {
  16017. isSuccess = ConfigurationStatus_Rejected;
  16018. }
  16019. }
  16020. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16021. {
  16022. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16023. {
  16024. check_ascii = value[0];
  16025. if( (check_ascii < 48) || (check_ascii > 57) )
  16026. {
  16027. isSuccess = ConfigurationStatus_Rejected;
  16028. }
  16029. else
  16030. {
  16031. if((atoi(value) == 0) || (atoi(value) >= 3))
  16032. {
  16033. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16034. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16035. isSuccess = ConfigurationStatus_Accepted;
  16036. }
  16037. else
  16038. {
  16039. isSuccess = ConfigurationStatus_Rejected;
  16040. }
  16041. }
  16042. }
  16043. else
  16044. {
  16045. isSuccess = ConfigurationStatus_Rejected;
  16046. }
  16047. }
  16048. if(strcmp(key, "MinimumStatusDuration") == 0)
  16049. {
  16050. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16051. {
  16052. check_ascii = value[0];
  16053. if( (check_ascii < 48) || (check_ascii > 57) )
  16054. {
  16055. isSuccess = ConfigurationStatus_Rejected;
  16056. }
  16057. else
  16058. {
  16059. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16060. {
  16061. isSuccess = ConfigurationStatus_Rejected;
  16062. }
  16063. else
  16064. {
  16065. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16066. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16067. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16068. isSuccess = ConfigurationStatus_Accepted;
  16069. }
  16070. }
  16071. }
  16072. else
  16073. {
  16074. isSuccess = ConfigurationStatus_Rejected;
  16075. }
  16076. }
  16077. if(strcmp(key, "NumberOfConnectors") == 0)
  16078. {
  16079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16080. {
  16081. check_ascii = value[0];
  16082. if( (check_ascii < 48) || (check_ascii > 57) )
  16083. {
  16084. isSuccess = ConfigurationStatus_Rejected;
  16085. }
  16086. else
  16087. {
  16088. //Charger.ResetRetries = Integer.parseInt(value);
  16089. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16090. isSuccess = ConfigurationStatus_Accepted;
  16091. }
  16092. }
  16093. else
  16094. {
  16095. isSuccess = ConfigurationStatus_Rejected;
  16096. }
  16097. }
  16098. if(strcmp(key, "ResetRetries") == 0)
  16099. {
  16100. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16101. {
  16102. check_ascii = value[0];
  16103. if( (check_ascii < 48) || (check_ascii > 57) )
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. else
  16108. {
  16109. //Charger.ResetRetries = Integer.parseInt(value);
  16110. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16111. isSuccess = ConfigurationStatus_Accepted;
  16112. }
  16113. }
  16114. else
  16115. {
  16116. isSuccess = ConfigurationStatus_Rejected;
  16117. }
  16118. }
  16119. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16120. {
  16121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16122. {
  16123. strcpy(str, (const char*)value);
  16124. for(int i = 0; str[i]; i++)
  16125. {
  16126. str[i] = tolower(str[i]);
  16127. }
  16128. if(strcmp(str, "notapplicable")== 0)
  16129. {
  16130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16131. isSuccess = ConfigurationStatus_Accepted;
  16132. }
  16133. else if(strcmp(str, "unknown")== 0)
  16134. {
  16135. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16136. isSuccess = ConfigurationStatus_Accepted;
  16137. }
  16138. else if(strcmp(str, "rst")== 0)
  16139. {
  16140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16141. isSuccess = ConfigurationStatus_Accepted;
  16142. }
  16143. else if(strcmp(str, "rts")== 0)
  16144. {
  16145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16146. isSuccess = ConfigurationStatus_Accepted;
  16147. }
  16148. else if(strcmp(str, "srt")== 0)
  16149. {
  16150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16151. isSuccess = ConfigurationStatus_Accepted;
  16152. }
  16153. else if(strcmp(str, "str")== 0)
  16154. {
  16155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16156. isSuccess = ConfigurationStatus_Accepted;
  16157. }
  16158. else if(strcmp(str, "trs")== 0)
  16159. {
  16160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16161. isSuccess = ConfigurationStatus_Accepted;
  16162. }
  16163. else if(strcmp(str, "tsr")== 0)
  16164. {
  16165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16166. isSuccess = ConfigurationStatus_Accepted;
  16167. }
  16168. else
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. }
  16173. else
  16174. {
  16175. isSuccess = ConfigurationStatus_Rejected;
  16176. }
  16177. }
  16178. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16179. {
  16180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16181. {
  16182. check_ascii = value[0];
  16183. if( (check_ascii < 48) || (check_ascii > 57) )
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. else
  16188. {
  16189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16190. isSuccess = ConfigurationStatus_Accepted;
  16191. }
  16192. }
  16193. else
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. }
  16198. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16199. {
  16200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16201. {
  16202. strcpy(str, (const char*)value);
  16203. for(int i = 0; str[i]; i++)
  16204. {
  16205. str[i] = tolower(str[i]);
  16206. }
  16207. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16209. isSuccess = ConfigurationStatus_Accepted;
  16210. }
  16211. else
  16212. {
  16213. isSuccess = ConfigurationStatus_Rejected;
  16214. }
  16215. }
  16216. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16217. {
  16218. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16219. {
  16220. strcpy(str, (const char*)value);
  16221. for(int i = 0; str[i]; i++)
  16222. {
  16223. str[i] = tolower(str[i]);
  16224. }
  16225. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. else
  16230. {
  16231. isSuccess = ConfigurationStatus_Rejected;
  16232. }
  16233. }
  16234. if(strcmp(key, "StopTxnAlignedData") == 0)
  16235. {
  16236. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16237. {
  16238. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16239. isSuccess = ConfigurationStatus_Accepted;
  16240. }
  16241. else
  16242. {
  16243. isSuccess = ConfigurationStatus_Rejected;
  16244. }
  16245. }
  16246. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16247. {
  16248. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16249. {
  16250. check_ascii = value[0];
  16251. if( (check_ascii < 48) || (check_ascii > 57) )
  16252. {
  16253. isSuccess = ConfigurationStatus_Rejected;
  16254. }
  16255. else
  16256. {
  16257. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16258. isSuccess = ConfigurationStatus_Accepted;
  16259. }
  16260. }
  16261. else
  16262. {
  16263. isSuccess = ConfigurationStatus_Rejected;
  16264. }
  16265. }
  16266. if(strcmp(key, "StopTxnSampledData") == 0)
  16267. {
  16268. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16269. {
  16270. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16271. isSuccess = ConfigurationStatus_Accepted;
  16272. }
  16273. else
  16274. {
  16275. isSuccess = ConfigurationStatus_Rejected;
  16276. }
  16277. }
  16278. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16279. {
  16280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16281. {
  16282. check_ascii = value[0];
  16283. if( (check_ascii < 48) || (check_ascii > 57) )
  16284. {
  16285. isSuccess = ConfigurationStatus_Rejected;
  16286. }
  16287. else
  16288. {
  16289. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16290. isSuccess = ConfigurationStatus_Accepted;
  16291. }
  16292. }
  16293. else
  16294. {
  16295. isSuccess = ConfigurationStatus_Rejected;
  16296. }
  16297. }
  16298. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16299. {
  16300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16301. {
  16302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16303. isSuccess = ConfigurationStatus_Accepted;
  16304. }
  16305. else
  16306. {
  16307. isSuccess = ConfigurationStatus_Rejected;
  16308. }
  16309. }
  16310. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16311. {
  16312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16313. {
  16314. check_ascii = value[0];
  16315. if( (check_ascii < 48) || (check_ascii > 57) )
  16316. {
  16317. isSuccess = ConfigurationStatus_Rejected;
  16318. }
  16319. else
  16320. {
  16321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16322. isSuccess = ConfigurationStatus_Accepted;
  16323. }
  16324. }
  16325. else
  16326. {
  16327. isSuccess = ConfigurationStatus_Rejected;
  16328. }
  16329. }
  16330. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16331. {
  16332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16333. {
  16334. check_ascii = value[0];
  16335. if( (check_ascii < 48) || (check_ascii > 57) )
  16336. {
  16337. isSuccess = ConfigurationStatus_Rejected;
  16338. }
  16339. else
  16340. {
  16341. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16343. TransactionMessageAttemptsValue = atoi(value);
  16344. isSuccess = ConfigurationStatus_Accepted;
  16345. }
  16346. }
  16347. else
  16348. {
  16349. isSuccess = ConfigurationStatus_Rejected;
  16350. }
  16351. }
  16352. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16353. {
  16354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16355. {
  16356. check_ascii = value[0];
  16357. if( (check_ascii < 48) || (check_ascii > 57) )
  16358. {
  16359. isSuccess = ConfigurationStatus_Rejected;
  16360. }
  16361. else
  16362. {
  16363. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16365. TransactionMessageRetryIntervalValue = atoi(value);
  16366. isSuccess = ConfigurationStatus_Accepted;
  16367. }
  16368. }
  16369. else
  16370. {
  16371. isSuccess = ConfigurationStatus_Rejected;
  16372. }
  16373. }
  16374. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16375. {
  16376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16377. {
  16378. strcpy(str, (const char*)value);
  16379. for(int i = 0; str[i]; i++)
  16380. {
  16381. str[i] = tolower(str[i]);
  16382. }
  16383. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16385. isSuccess = ConfigurationStatus_Accepted;
  16386. }
  16387. else
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. }
  16392. if(strcmp(key, "WebSocketPingInterval") == 0)
  16393. {
  16394. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16395. {
  16396. check_ascii = value[0];
  16397. if( (check_ascii < 48) || (check_ascii > 57) )
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. else
  16402. {
  16403. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16404. isSuccess = ConfigurationStatus_Accepted;
  16405. if((atoi(value) == 0) || (atoi(value) >= 10))
  16406. {
  16407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16408. isSuccess = ConfigurationStatus_Accepted;
  16409. }
  16410. else
  16411. isSuccess = ConfigurationStatus_Rejected;
  16412. }
  16413. }
  16414. else
  16415. {
  16416. isSuccess = ConfigurationStatus_Rejected;
  16417. }
  16418. }
  16419. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16420. {
  16421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16422. {
  16423. strcpy(str, (const char*)value);
  16424. for(int i = 0; str[i]; i++)
  16425. {
  16426. str[i] = tolower(str[i]);
  16427. }
  16428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16429. isSuccess = ConfigurationStatus_Accepted;
  16430. }
  16431. else
  16432. {
  16433. isSuccess = ConfigurationStatus_Rejected;
  16434. }
  16435. }
  16436. if(strcmp(key, "AuthorizationKey") == 0)
  16437. {
  16438. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16439. {
  16440. strcpy(str, (const char*)value);
  16441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16442. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16443. isSuccess = ConfigurationStatus_Accepted;
  16444. }
  16445. else
  16446. {
  16447. isSuccess = ConfigurationStatus_Rejected;
  16448. }
  16449. }
  16450. if(strcmp(key, "SecurityProfile") == 0)
  16451. {
  16452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16453. {
  16454. check_ascii = value[0];
  16455. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16456. {
  16457. isSuccess = ConfigurationStatus_Rejected;
  16458. }
  16459. else if(check_ascii == 0x33)
  16460. {
  16461. isSuccess = NotSupported;
  16462. }
  16463. else
  16464. {
  16465. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16466. {
  16467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16468. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16469. isSuccess = ConfigurationStatus_Accepted;
  16470. }
  16471. else
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. }
  16475. else
  16476. {
  16477. isSuccess = ConfigurationStatus_Rejected;
  16478. }
  16479. }
  16480. if(strcmp(key, "DefaultPrice") == 0)
  16481. {
  16482. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16483. {
  16484. strcpy(str, (const char*)value);
  16485. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16486. isSuccess = ConfigurationStatus_Accepted;
  16487. }
  16488. else
  16489. {
  16490. isSuccess = ConfigurationStatus_Rejected;
  16491. }
  16492. }
  16493. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16494. {
  16495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16496. {
  16497. strcpy(str, (const char*)value);
  16498. for(int i = 0; str[i]; i++)
  16499. {
  16500. str[i] = tolower(str[i]);
  16501. }
  16502. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16503. isSuccess = ConfigurationStatus_Accepted;
  16504. }
  16505. else
  16506. {
  16507. isSuccess = ConfigurationStatus_Rejected;
  16508. }
  16509. }
  16510. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16511. {
  16512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16513. {
  16514. strcpy(str, (const char*)value);
  16515. for(int i = 0; str[i]; i++)
  16516. {
  16517. str[i] = tolower(str[i]);
  16518. }
  16519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16520. isSuccess = ConfigurationStatus_Accepted;
  16521. }
  16522. else
  16523. {
  16524. isSuccess = ConfigurationStatus_Rejected;
  16525. }
  16526. }
  16527. if(strcmp(key, "SystemUptimeSec") == 0)
  16528. {
  16529. isSuccess = NotSupported;
  16530. }
  16531. if(strcmp(key, "FreeVend") == 0)
  16532. {
  16533. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16534. {
  16535. strcpy(str, (const char*)value);
  16536. for(int i = 0; str[i]; i++)
  16537. {
  16538. str[i] = tolower(str[i]);
  16539. }
  16540. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16542. isSuccess = ConfigurationStatus_Accepted;
  16543. }
  16544. else
  16545. {
  16546. isSuccess = ConfigurationStatus_Rejected;
  16547. }
  16548. }
  16549. if(strcmp(key, "FreeVendIdtag") == 0)
  16550. {
  16551. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16552. {
  16553. strcpy(str, (const char*)value);
  16554. if(strlen(str) <= 20)
  16555. {
  16556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16557. isSuccess = ConfigurationStatus_Accepted;
  16558. }
  16559. else
  16560. {
  16561. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16562. isSuccess = ConfigurationStatus_Rejected;
  16563. }
  16564. }
  16565. else
  16566. {
  16567. isSuccess = ConfigurationStatus_Rejected;
  16568. }
  16569. }
  16570. if(strcmp(key, "OcppServer") == 0)
  16571. {
  16572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16573. {
  16574. strcpy(str, (const char*)value);
  16575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16576. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16577. isSuccess = ConfigurationStatus_Accepted;
  16578. }
  16579. else
  16580. {
  16581. isSuccess = ConfigurationStatus_Rejected;
  16582. }
  16583. }
  16584. if(strcmp(key, "MaintainServer") == 0)
  16585. {
  16586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16587. {
  16588. strcpy(str, (const char*)value);
  16589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16590. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16591. isSuccess = ConfigurationStatus_Accepted;
  16592. }
  16593. else
  16594. {
  16595. isSuccess = ConfigurationStatus_Rejected;
  16596. }
  16597. }
  16598. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16599. {
  16600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16601. {
  16602. strcpy(str, (const char*)value);
  16603. for(int i = 0; str[i]; i++)
  16604. {
  16605. str[i] = tolower(str[i]);
  16606. }
  16607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16608. isSuccess = ConfigurationStatus_Accepted;
  16609. }
  16610. else
  16611. {
  16612. isSuccess = ConfigurationStatus_Rejected;
  16613. }
  16614. }
  16615. if(strcmp(key, "StatusNotificationInterval") == 0)
  16616. {
  16617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16618. {
  16619. check_ascii = value[0];
  16620. if( (check_ascii < 48) || (check_ascii > 57) )
  16621. {
  16622. isSuccess = ConfigurationStatus_Rejected;
  16623. }
  16624. else
  16625. {
  16626. if((atoi(value) == 0) || (atoi(value) >= 10))
  16627. {
  16628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16629. isSuccess = ConfigurationStatus_Accepted;
  16630. }
  16631. else
  16632. isSuccess = ConfigurationStatus_Rejected;
  16633. }
  16634. }
  16635. else
  16636. {
  16637. isSuccess = ConfigurationStatus_Rejected;
  16638. }
  16639. }
  16640. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16641. {
  16642. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16643. {
  16644. check_ascii = value[0];
  16645. if( (check_ascii < 48) || (check_ascii > 57) )
  16646. {
  16647. isSuccess = ConfigurationStatus_Rejected;
  16648. }
  16649. else
  16650. {
  16651. if(atoi(value) >= 0)
  16652. {
  16653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16654. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16655. isSuccess = ConfigurationStatus_Accepted;
  16656. }
  16657. else
  16658. isSuccess = ConfigurationStatus_Rejected;
  16659. }
  16660. }
  16661. else
  16662. {
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. }
  16666. if(strcmp(key, "PowerSharingServerIP") == 0)
  16667. {
  16668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16669. {
  16670. strcpy(str, (const char*)value);
  16671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16672. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16673. isSuccess = ConfigurationStatus_Accepted;
  16674. }
  16675. else
  16676. {
  16677. isSuccess = ConfigurationStatus_Rejected;
  16678. }
  16679. }
  16680. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16681. {
  16682. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16683. {
  16684. strcpy(str, (const char*)value);
  16685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16686. isSuccess = ConfigurationStatus_Accepted;
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. #if 0
  16694. //For OCPP Test Case
  16695. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16696. {
  16697. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16698. {
  16699. strcpy(str, (const char*)value);
  16700. for(int i = 0; str[i]; i++)
  16701. {
  16702. str[i] = tolower(str[i]);
  16703. }
  16704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16707. }
  16708. else
  16709. {
  16710. isSuccess = ConfigurationStatus_Rejected;
  16711. }
  16712. }
  16713. #endif
  16714. #if 1
  16715. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16716. {
  16717. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16718. {
  16719. strcpy(str, (const char*)value);
  16720. for(int i = 0; str[i]; i++)
  16721. {
  16722. str[i] = tolower(str[i]);
  16723. }
  16724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16725. isSuccess = ConfigurationStatus_Accepted;
  16726. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16727. }
  16728. else
  16729. {
  16730. isSuccess = ConfigurationStatus_Rejected;
  16731. }
  16732. }
  16733. #endif
  16734. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16735. {
  16736. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16737. {
  16738. check_ascii = value[0];
  16739. if( (check_ascii < 48) || (check_ascii > 57) )
  16740. {
  16741. isSuccess = ConfigurationStatus_Rejected;
  16742. }
  16743. else
  16744. {
  16745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16746. isSuccess = ConfigurationStatus_Accepted;
  16747. }
  16748. }
  16749. else
  16750. {
  16751. isSuccess = ConfigurationStatus_Rejected;
  16752. }
  16753. }
  16754. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16755. {
  16756. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16757. {
  16758. check_ascii = value[0];
  16759. if( (check_ascii < 48) || (check_ascii > 57) )
  16760. {
  16761. isSuccess = ConfigurationStatus_Rejected;
  16762. }
  16763. else
  16764. {
  16765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16766. isSuccess = ConfigurationStatus_Accepted;
  16767. }
  16768. }
  16769. else
  16770. {
  16771. isSuccess = ConfigurationStatus_Rejected;
  16772. }
  16773. }
  16774. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16775. {
  16776. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16777. {
  16778. strcpy(str, (const char*)value);
  16779. for(int i = 0; str[i]; i++)
  16780. {
  16781. str[i] = tolower(str[i]);
  16782. }
  16783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16784. isSuccess = ConfigurationStatus_Accepted;
  16785. }
  16786. else
  16787. {
  16788. isSuccess = ConfigurationStatus_Rejected;
  16789. }
  16790. }
  16791. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16792. {
  16793. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16794. {
  16795. check_ascii = value[0];
  16796. if( (check_ascii < 48) || (check_ascii > 57) )
  16797. {
  16798. isSuccess = ConfigurationStatus_Rejected;
  16799. }
  16800. else
  16801. {
  16802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16803. isSuccess = ConfigurationStatus_Accepted;
  16804. }
  16805. }
  16806. else
  16807. {
  16808. isSuccess = ConfigurationStatus_Rejected;
  16809. }
  16810. }
  16811. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16812. {
  16813. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16814. {
  16815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16816. isSuccess = ConfigurationStatus_Accepted;
  16817. }
  16818. else
  16819. {
  16820. isSuccess = ConfigurationStatus_Rejected;
  16821. }
  16822. }
  16823. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16824. {
  16825. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16826. {
  16827. check_ascii = value[0];
  16828. if( (check_ascii < 48) || (check_ascii > 57) )
  16829. {
  16830. isSuccess = ConfigurationStatus_Rejected;
  16831. }
  16832. else
  16833. {
  16834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16835. isSuccess = ConfigurationStatus_Accepted;
  16836. }
  16837. }
  16838. else
  16839. {
  16840. isSuccess = ConfigurationStatus_Rejected;
  16841. }
  16842. }
  16843. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16844. {
  16845. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16846. {
  16847. strcpy(str, (const char*)value);
  16848. for(int i = 0; str[i]; i++)
  16849. {
  16850. str[i] = tolower(str[i]);
  16851. }
  16852. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16853. isSuccess = ConfigurationStatus_Accepted;
  16854. }
  16855. else
  16856. {
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. }
  16860. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16861. {
  16862. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16863. {
  16864. check_ascii = value[0];
  16865. if( (check_ascii < 48) || (check_ascii > 57) )
  16866. {
  16867. isSuccess = ConfigurationStatus_Rejected;
  16868. }
  16869. else
  16870. {
  16871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16872. isSuccess = ConfigurationStatus_Accepted;
  16873. }
  16874. }
  16875. else
  16876. {
  16877. isSuccess = ConfigurationStatus_Rejected;
  16878. }
  16879. }
  16880. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16881. return isSuccess;
  16882. }
  16883. int TransactionMessageAttemptsGet(void)
  16884. {
  16885. return TransactionMessageAttemptsValue;
  16886. }
  16887. int FirstHeartBeatResponse(void)
  16888. {
  16889. return FirstHeartBeat;
  16890. }
  16891. int TransactionMessageRetryIntervalGet(void)
  16892. {
  16893. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16894. }
  16895. int ReadHttpStatus(int sock)
  16896. {
  16897. //char c;
  16898. char buff[1024]="",*ptr=buff+1;
  16899. int bytes_received, status;
  16900. DEBUG_INFO("Begin Response ..\n");
  16901. while((bytes_received = recv(sock, ptr, 1, 0))){
  16902. if(bytes_received==-1){
  16903. perror("ReadHttpStatus");
  16904. exit(1);
  16905. }
  16906. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16907. ptr++;
  16908. }
  16909. *ptr=0;
  16910. ptr=buff+1;
  16911. sscanf(ptr,"%*s %d ", &status);
  16912. DEBUG_INFO("%s\n",ptr);
  16913. DEBUG_INFO("status=%d\n",status);
  16914. DEBUG_INFO("End Response ..\n");
  16915. return (bytes_received>0)?status:0;
  16916. }
  16917. //the only filed that it parsed is 'Content-Length'
  16918. int ParseHeader(int sock)
  16919. {
  16920. //char c;
  16921. char buff[1024]="",*ptr=buff+4;
  16922. int bytes_received;
  16923. DEBUG_INFO("Begin HEADER ..\n");
  16924. while((bytes_received = recv(sock, ptr, 1, 0))){
  16925. if(bytes_received==-1){
  16926. perror("Parse Header");
  16927. exit(1);
  16928. }
  16929. if(
  16930. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16931. (ptr[-1]=='\r') && (*ptr=='\n' )
  16932. ) break;
  16933. ptr++;
  16934. }
  16935. *ptr=0;
  16936. ptr=buff+4;
  16937. //printf("%s",ptr);
  16938. if(bytes_received){
  16939. ptr=strstr(ptr,"Content-Length:");
  16940. if(ptr){
  16941. sscanf(ptr,"%*s %d",&bytes_received);
  16942. }else
  16943. bytes_received=-1; //unknown size
  16944. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16945. }
  16946. DEBUG_INFO("End HEADER ..\n");
  16947. return bytes_received ;
  16948. }
  16949. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16950. {
  16951. int result = TRUE;
  16952. char rmFileCmd[100]={0};
  16953. char FilePath[100]={0};
  16954. char ftpbuf[200];
  16955. int systemresult;
  16956. sprintf(FilePath,"/mnt/%s",filename);
  16957. system("ping 8.8.8.8 &");
  16958. if((access(FilePath,F_OK))!=-1)
  16959. {
  16960. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16961. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16962. system(rmFileCmd);
  16963. }
  16964. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16965. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16966. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16967. systemresult = system(ftpbuf);
  16968. if(systemresult != 0)
  16969. {
  16970. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  16971. result = FALSE;
  16972. }
  16973. system("pkill ping");
  16974. return result;
  16975. }
  16976. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16977. {
  16978. int result = TRUE;
  16979. char rmFileCmd[100]={0};
  16980. char FilePath[100]={0};
  16981. char ftpbuf[200];
  16982. int systemresult;
  16983. sprintf(FilePath,"/mnt/%s",filename);
  16984. system("ping 8.8.8.8 &");
  16985. if((access(FilePath,F_OK))!=-1)
  16986. {
  16987. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16988. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16989. system(rmFileCmd);
  16990. }
  16991. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16992. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  16993. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16994. systemresult = system(ftpbuf);
  16995. if(systemresult != 0)
  16996. {
  16997. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16998. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16999. systemresult = system(ftpbuf);
  17000. if(systemresult != 0)
  17001. {
  17002. DEBUG_WARN("FTP download fail!\n");
  17003. result = FALSE;
  17004. }
  17005. }
  17006. system("pkill ping");
  17007. return result;
  17008. }
  17009. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17010. {
  17011. char rmFileCmd[100]={0};
  17012. char FilePath[100]={0};
  17013. char buf[512];
  17014. int systemresult = 0;
  17015. //DEBUG_INFO("filename=%s\n",filename);
  17016. //DEBUG_INFO("url=%s\n",url);
  17017. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17018. if((access(FilePath,F_OK))!=-1)
  17019. {
  17020. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17021. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17022. system(rmFileCmd);
  17023. }
  17024. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17025. if(fp == NULL)
  17026. {
  17027. DEBUG_INFO("log is NULL\n");
  17028. return FALSE;
  17029. }
  17030. else
  17031. {
  17032. fprintf(fp, "%s\n", url);
  17033. fprintf(fp, "%s\n", filename);
  17034. fclose(fp);
  17035. }
  17036. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17037. if(phpFP == NULL)
  17038. {
  17039. DEBUG_INFO("PHP upload fail.\n");
  17040. return FALSE;
  17041. }
  17042. else
  17043. {
  17044. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17045. {
  17046. if(strstr(buf, "result") != NULL)
  17047. {
  17048. sscanf(buf, "result: %d", &systemresult);
  17049. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17050. }
  17051. }
  17052. pclose(phpFP);
  17053. }
  17054. if(systemresult != 1)
  17055. {
  17056. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17057. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17058. if(phpFP == NULL)
  17059. {
  17060. DEBUG_WARN("PHP PUT upload fail.\n");
  17061. return FALSE;
  17062. }
  17063. else
  17064. {
  17065. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17066. {
  17067. if(strstr(buf, "result") != NULL)
  17068. {
  17069. sscanf(buf, "result: %d", &systemresult);
  17070. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17071. }
  17072. }
  17073. pclose(phpFP);
  17074. }
  17075. }
  17076. if(systemresult != 1)
  17077. {
  17078. DEBUG_WARN("PHP PUT upload fail.\n");
  17079. return FALSE;
  17080. }
  17081. return TRUE;
  17082. }
  17083. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17084. {
  17085. int result = FALSE;
  17086. char ftpbuf[200];
  17087. int systemresult;
  17088. /*
  17089. // Domaind name transfer to IP address
  17090. struct hostent* server;
  17091. char *IPbuffer;
  17092. server = gethostbyname(location);
  17093. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17094. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17095. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17096. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17097. systemresult = system(ftpbuf);
  17098. if(systemresult != 0)
  17099. {
  17100. DEBUG_INFO("ftpput error!\n");
  17101. }
  17102. else
  17103. {
  17104. result = TRUE;
  17105. DEBUG_INFO("ftpput OK!\n");
  17106. }
  17107. return result;
  17108. }
  17109. int GetOcppServerURL()
  17110. {
  17111. int result = FALSE;
  17112. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17113. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17114. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17115. struct yuarel url;
  17116. char urlStr[512];
  17117. // OCPPPH only
  17118. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17119. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17120. {
  17121. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17122. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17123. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17124. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17125. if(yuarel_parse(&url, urlStr) != -1)
  17126. {
  17127. sprintf(OcppProtocol, "%s", url.scheme);
  17128. sprintf(OcppHost, "%s", url.host);
  17129. if(url.path == NULL)
  17130. OcppTempPath[0] = '\0';
  17131. else
  17132. sprintf(OcppTempPath, "%s", url.path);
  17133. if(url.port == 0)
  17134. {
  17135. if(strcmp(OcppProtocol, "wss") == 0)
  17136. OcppPort = 443;
  17137. else
  17138. OcppPort = 80;
  17139. }
  17140. else
  17141. OcppPort = url.port;
  17142. result = TRUE;
  17143. }
  17144. }
  17145. else
  17146. {
  17147. strcpy(OcppHost,"");
  17148. }
  17149. return result;
  17150. }
  17151. int GetOcppPath()
  17152. {
  17153. int result = FALSE;
  17154. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17155. {
  17156. if(OcppTempPath == NULL)
  17157. {
  17158. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17159. }
  17160. else
  17161. {
  17162. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17163. }
  17164. result = TRUE;
  17165. goto End;
  17166. }
  17167. else
  17168. {
  17169. strcpy(OcppPath,"");
  17170. }
  17171. End:
  17172. return result;
  17173. }
  17174. int GetOcppPort()
  17175. {
  17176. return OcppPort;
  17177. }
  17178. int GetOcppConnStatus(void)
  17179. {
  17180. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17181. }
  17182. void SetOcppConnStatus(uint8_t status)
  17183. {
  17184. ShmOCPP16DataPH->OcppConnStatus = status;
  17185. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17186. }
  17187. int GetHeartBeatWithNOResponse(void)
  17188. {
  17189. return HeartBeatWithNOResponse;
  17190. }
  17191. void SetHeartBeatWithNOResponse(void)
  17192. {
  17193. HeartBeatWithNOResponse = 0;
  17194. }
  17195. void GetStartTransactionIdTag(int gun_index)
  17196. {
  17197. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17198. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17199. }
  17200. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17201. {
  17202. char ch;
  17203. FILE *fptr1;
  17204. int temptransactionId;
  17205. char str[100]={0};
  17206. temptransactionId = 0;
  17207. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17208. {
  17209. DEBUG_INFO("IdTag is empty.\n");
  17210. return temptransactionId;
  17211. }
  17212. /*------ Read the file ----------------*/
  17213. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17214. if (!fptr1)
  17215. {
  17216. DEBUG_INFO("QueueTransactionId file open error.\n");
  17217. //printf(" File not found or unable to open the input file!!\n");
  17218. return temptransactionId;
  17219. }
  17220. ch=fgetc(fptr1);
  17221. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17222. rewind(fptr1);
  17223. if(ch!=EOF)
  17224. {
  17225. // printf("%c",ch);
  17226. while (fgets(str, 100, fptr1) != NULL)
  17227. {
  17228. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17229. if(str[0]=='\0')
  17230. {
  17231. break;
  17232. }
  17233. char *revbuf[8] = {0}; // Variable store string split
  17234. int num = 0;// Quantity after string split
  17235. DEBUG_INFO("Transaction queue data= %s\n", str);
  17236. splitstring(str,",",revbuf,&num); // String split
  17237. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17238. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17239. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17240. DEBUG_INFO("------------------------------\n");
  17241. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17242. {
  17243. if(isStopTransaction)
  17244. {
  17245. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17246. {
  17247. temptransactionId = atoi(revbuf[2]);
  17248. //break;
  17249. }
  17250. }
  17251. else
  17252. {
  17253. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17254. {
  17255. temptransactionId = atoi(revbuf[2]);
  17256. //break;
  17257. }
  17258. }
  17259. }
  17260. }
  17261. }
  17262. else
  17263. DEBUG_INFO("EOF\n");
  17264. fclose(fptr1);
  17265. /*------- End of reading ---------------*/
  17266. return temptransactionId;
  17267. }
  17268. void SetTransactionIdZero(int transactionId)
  17269. {
  17270. char ch;
  17271. FILE *fptr1, *fptr2;
  17272. int temptransactionId = 0;
  17273. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17274. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17275. if (!fptr1)
  17276. {
  17277. //printf(" File not found or unable to open the input file!!\n");
  17278. return ;
  17279. }
  17280. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17281. if (!fptr2)
  17282. {
  17283. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17284. fclose(fptr1);
  17285. return ;
  17286. }
  17287. ch=fgetc(fptr1);
  17288. rewind(fptr1);
  17289. if(ch!=EOF)
  17290. {
  17291. // copy all contents to the temporary file except the specific line
  17292. while (fgets(str, 100, fptr1) != NULL)
  17293. {
  17294. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17295. if(str[0]=='\0')
  17296. {
  17297. break;
  17298. }
  17299. char *revbuf[8] = {0};
  17300. int num = 0;
  17301. strcpy(strtemp, str);
  17302. splitstring(str,",",revbuf,&num);
  17303. if(revbuf[2][0] != '\0')
  17304. {
  17305. temptransactionId = atoi(revbuf[2]);
  17306. if(transactionId != temptransactionId)
  17307. {
  17308. fprintf(fptr2, "%s\n", strtemp);
  17309. }
  17310. }
  17311. }
  17312. }
  17313. fclose(fptr1);
  17314. fclose(fptr2);
  17315. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17316. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17317. /*------ Read the file ----------------*/
  17318. }
  17319. int InternetDisconnect(void)
  17320. {
  17321. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17322. }
  17323. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17324. void storeTempStopTransaction(int gun_index)
  17325. {
  17326. char guid[37]={0};
  17327. int tempIndex = 0;
  17328. char TempStopTransaction[256];
  17329. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17330. DEBUG_INFO("storeTempStopTransaction...\n");
  17331. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17332. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17333. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17336. {
  17337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17338. {
  17339. tempIndex = ((gun_index==2) ? 1: 0);
  17340. }
  17341. else
  17342. {
  17343. tempIndex = gun_index;
  17344. }
  17345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17346. {
  17347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17348. {
  17349. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17350. }
  17351. }// END OF CHAdeMO_QUANTITY
  17352. }
  17353. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17354. {
  17355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17356. {
  17357. tempIndex = ((gun_index==2) ? 1: 0);
  17358. }
  17359. else
  17360. {
  17361. tempIndex = gun_index;
  17362. }
  17363. for (int index = 0; index < CCS_QUANTITY; index++)
  17364. {
  17365. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17366. {
  17367. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17368. }
  17369. }// END OF CCS_QUANTITY
  17370. }
  17371. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17372. {
  17373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17374. {
  17375. tempIndex = ((gun_index==2) ? 1: 0);
  17376. }
  17377. else
  17378. {
  17379. tempIndex = gun_index;
  17380. }
  17381. for (int index = 0; index < GB_QUANTITY; index++)
  17382. {
  17383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17384. {
  17385. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17386. }
  17387. }// END OF GB_QUANTITY
  17388. }
  17389. else if(gunType[gun_index] == GUN_TYPE_DO)
  17390. {
  17391. tempIndex = gun_index;
  17392. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17393. {
  17394. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17395. {
  17396. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17397. }
  17398. }
  17399. }
  17400. else
  17401. {
  17402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17403. {
  17404. tempIndex = 2;
  17405. }
  17406. else
  17407. {
  17408. tempIndex = gun_index;
  17409. }
  17410. for (int index = 0; index < AC_QUANTITY; index++)
  17411. {
  17412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17413. {
  17414. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17415. }
  17416. }// END OF AC_QUANTITY
  17417. }
  17418. //Stop Transaction Time
  17419. struct timeval tmnow;
  17420. struct tm *tm;
  17421. char buf[28];//, usec_buf[6];
  17422. gettimeofday(&tmnow, NULL);
  17423. time_t t;
  17424. t = time(NULL);
  17425. /*UTC time and date*/
  17426. tm = gmtime(&t);
  17427. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17429. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17430. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17431. random_uuid(guid);
  17432. /***********************************transactionData******************************************************/
  17433. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17435. //=================================
  17436. //1. Transaction_Begin
  17437. //=================================
  17438. //============================== Energy.Active.Import.Interval ===========================================
  17439. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17440. {
  17441. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17443. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17444. 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*/]);
  17445. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17446. 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))
  17447. {
  17448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17449. }
  17450. else
  17451. {
  17452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17453. }
  17454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17456. }
  17457. //=================================
  17458. //2. Transaction_End
  17459. //=================================
  17460. //2.1====================================== Current.Import L1 ==============================================
  17461. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17462. {
  17463. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17464. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17465. {
  17466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17467. {
  17468. tempIndex = ((gun_index==2) ? 1: 0);
  17469. }
  17470. else
  17471. {
  17472. tempIndex = gun_index;
  17473. }
  17474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17475. {
  17476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17477. {
  17478. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17479. }
  17480. }// End of for CHAdeMO_QUANTITY
  17481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17482. }
  17483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17484. {
  17485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17486. {
  17487. tempIndex = ((gun_index==2) ? 1: 0);
  17488. }
  17489. else
  17490. {
  17491. tempIndex = gun_index;
  17492. }
  17493. for (int index = 0; index < CCS_QUANTITY; index++)
  17494. {
  17495. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17496. {
  17497. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17498. }
  17499. }// End of for CCS_QUANTITY
  17500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17501. }
  17502. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17503. {
  17504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17505. {
  17506. tempIndex = ((gun_index==2) ? 1: 0);
  17507. }
  17508. else
  17509. {
  17510. tempIndex = gun_index;
  17511. }
  17512. for (int index = 0; index < GB_QUANTITY; index++)
  17513. {
  17514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17515. {
  17516. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17517. }
  17518. }// End of for GB_QUANTITY
  17519. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17520. }
  17521. else if(gunType[gun_index] == GUN_TYPE_DO)
  17522. {
  17523. tempIndex = gun_index;
  17524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17525. {
  17526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17527. {
  17528. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17529. }
  17530. }
  17531. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17532. }
  17533. else
  17534. {
  17535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17536. {
  17537. tempIndex = 2;
  17538. }
  17539. else
  17540. {
  17541. tempIndex = gun_index;
  17542. }
  17543. for (int index = 0; index < AC_QUANTITY; index++)
  17544. {
  17545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17546. {
  17547. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17548. }
  17549. }// End of for AC_QUANTITY
  17550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17551. }
  17552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17555. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17558. }
  17559. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17560. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17561. {
  17562. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17564. {
  17565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17566. {
  17567. tempIndex = ((gun_index==2) ? 1: 0);
  17568. }
  17569. else
  17570. {
  17571. tempIndex = gun_index;
  17572. }
  17573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17574. {
  17575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17576. {
  17577. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17578. }
  17579. }// END OF CHAdeMO_QUANTITY
  17580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17581. }
  17582. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17583. {
  17584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17585. {
  17586. tempIndex = ((gun_index==2) ? 1: 0);
  17587. }
  17588. else
  17589. {
  17590. tempIndex = gun_index;
  17591. }
  17592. for (int index = 0; index < CCS_QUANTITY; index++)
  17593. {
  17594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17595. {
  17596. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17597. }
  17598. }// END OF CCS_QUANTITY
  17599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17600. }
  17601. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17602. {
  17603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17604. {
  17605. tempIndex = ((gun_index==2) ? 1: 0);
  17606. }
  17607. else
  17608. {
  17609. tempIndex = gun_index;
  17610. }
  17611. for (int index = 0; index < GB_QUANTITY; index++)
  17612. {
  17613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17614. {
  17615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17616. }
  17617. }// END OF GB_QUANTITY
  17618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17619. }
  17620. else if(gunType[gun_index] == GUN_TYPE_DO)
  17621. {
  17622. tempIndex = gun_index;
  17623. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17624. {
  17625. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17626. {
  17627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17628. }
  17629. }
  17630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17631. }
  17632. else
  17633. {
  17634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17635. {
  17636. tempIndex = 2;
  17637. }
  17638. else
  17639. {
  17640. tempIndex = gun_index;
  17641. }
  17642. for (int index = 0; index < AC_QUANTITY; index++)
  17643. {
  17644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17645. {
  17646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17647. }
  17648. }// END OF AC_QUANTITY
  17649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17650. }
  17651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17654. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17657. }
  17658. //2.3====================================== Power.Active.Import =========================================
  17659. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17660. {
  17661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17662. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17663. {
  17664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17665. {
  17666. tempIndex = ((gun_index==2) ? 1: 0);
  17667. }
  17668. else
  17669. {
  17670. tempIndex = gun_index;
  17671. }
  17672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17673. {
  17674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17675. {
  17676. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17677. }
  17678. } // End for CHAdeMO_QUANTITY
  17679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17680. }
  17681. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17682. {
  17683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17684. {
  17685. tempIndex = ((gun_index==2) ? 1: 0);
  17686. }
  17687. else
  17688. {
  17689. tempIndex = gun_index;
  17690. }
  17691. for (int index = 0; index < CCS_QUANTITY; index++)
  17692. {
  17693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17694. {
  17695. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17696. }
  17697. } // END for CCS_QUANTITY
  17698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17699. }
  17700. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17701. {
  17702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17703. {
  17704. tempIndex = ((gun_index==2) ? 1: 0);
  17705. }
  17706. else
  17707. {
  17708. tempIndex = gun_index;
  17709. }
  17710. for (int index = 0; index < GB_QUANTITY; index++)
  17711. {
  17712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17713. {
  17714. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17715. }
  17716. }// END for GB_QUANTITY
  17717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17718. }
  17719. else if(gunType[gun_index] == GUN_TYPE_DO)
  17720. {
  17721. tempIndex = gun_index;
  17722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17723. {
  17724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17725. {
  17726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17727. }
  17728. }
  17729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17730. }
  17731. else
  17732. {
  17733. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17734. {
  17735. tempIndex = 2;
  17736. }
  17737. else
  17738. {
  17739. tempIndex = gun_index;
  17740. }
  17741. for (int index = 0; index < AC_QUANTITY; index++)
  17742. {
  17743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17744. {
  17745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17746. }
  17747. } // END for AC_QUANTITY
  17748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17749. }
  17750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17753. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17756. }
  17757. //2.4====================================== Voltage L1 ====================================================
  17758. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17759. {
  17760. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17761. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17762. {
  17763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17764. {
  17765. tempIndex = ((gun_index==2) ? 1: 0);
  17766. }
  17767. else
  17768. {
  17769. tempIndex = gun_index;
  17770. }
  17771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17772. {
  17773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17774. {
  17775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17776. }
  17777. } // END OF FOR CHAdeMO_QUANTITY
  17778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17779. }
  17780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17781. {
  17782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17783. {
  17784. tempIndex = ((gun_index==2) ? 1: 0);
  17785. }
  17786. else
  17787. {
  17788. tempIndex = gun_index;
  17789. }
  17790. for (int index = 0; index < CCS_QUANTITY; index++)
  17791. {
  17792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17793. {
  17794. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17795. }
  17796. } // END OF FOR CCS_QUANTITY
  17797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17798. }
  17799. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17800. {
  17801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17802. {
  17803. tempIndex = ((gun_index==2) ? 1: 0);
  17804. }
  17805. else
  17806. {
  17807. tempIndex = gun_index;
  17808. }
  17809. for (int index = 0; index < GB_QUANTITY; index++)
  17810. {
  17811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17812. {
  17813. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17814. }
  17815. } // END OF FOR GB_QUANTITY
  17816. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17817. }
  17818. else if(gunType[gun_index] == GUN_TYPE_DO)
  17819. {
  17820. tempIndex = gun_index;
  17821. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17822. {
  17823. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17824. {
  17825. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17826. }
  17827. }
  17828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17829. }
  17830. else
  17831. {
  17832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17833. {
  17834. tempIndex = 2;
  17835. }
  17836. else
  17837. {
  17838. tempIndex = gun_index;
  17839. }
  17840. for (int index = 0; index < AC_QUANTITY; index++)
  17841. {
  17842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17843. {
  17844. 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
  17845. }
  17846. } // END OF FOR AC_QUANTITY
  17847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17848. }
  17849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17852. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17855. }
  17856. //2.5============================================== End SoC =========================================================
  17857. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17858. {
  17859. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17860. 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))
  17861. {
  17862. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17863. {
  17864. tempIndex = ((gun_index==2) ? 1: 0);
  17865. }
  17866. else
  17867. {
  17868. tempIndex = gun_index;
  17869. }
  17870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17871. {
  17872. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17873. {
  17874. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17875. {
  17876. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17877. }
  17878. }
  17879. }
  17880. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17881. {
  17882. for (int index = 0; index < CCS_QUANTITY; index++)
  17883. {
  17884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17885. {
  17886. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17887. }
  17888. }
  17889. }
  17890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17891. {
  17892. for (int index = 0; index < GB_QUANTITY; index++)
  17893. {
  17894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17895. {
  17896. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17897. }
  17898. }
  17899. }
  17900. else if(gunType[gun_index] == GUN_TYPE_DO)
  17901. {
  17902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17903. {
  17904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17905. {
  17906. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17907. }
  17908. }
  17909. }
  17910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17912. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17916. } // END FOR DC CASE
  17917. }
  17918. //2.6====================================== Current.Import L2 ==============================================
  17919. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17920. {
  17921. // AC 3 phase L2 current
  17922. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17923. {
  17924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17925. {
  17926. tempIndex = 2;
  17927. }
  17928. else
  17929. {
  17930. tempIndex = gun_index;
  17931. }
  17932. for (int index = 0; index < AC_QUANTITY; index++)
  17933. {
  17934. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17935. {
  17936. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17937. }
  17938. }// End of for AC_QUANTITY
  17939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17940. }
  17941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17946. }
  17947. //2.7====================================== Current.Import L3 ==============================================
  17948. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17949. {
  17950. // AC 3 phase L3 current
  17951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17952. {
  17953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17954. {
  17955. tempIndex = 2;
  17956. }
  17957. else
  17958. {
  17959. tempIndex = gun_index;
  17960. }
  17961. for (int index = 0; index < AC_QUANTITY; index++)
  17962. {
  17963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17964. {
  17965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17966. }
  17967. }// End of for AC_QUANTITY
  17968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17969. }
  17970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17975. }
  17976. //2.9====================================== Voltage L2 ====================================================
  17977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17978. {
  17979. // AC 3 phase L2 volatge
  17980. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17981. {
  17982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17983. {
  17984. tempIndex = 2;
  17985. }
  17986. else
  17987. {
  17988. tempIndex = gun_index;
  17989. }
  17990. for (int index = 0; index < AC_QUANTITY; index++)
  17991. {
  17992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17993. {
  17994. 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
  17995. }
  17996. } // END OF FOR AC_QUANTITY
  17997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17998. }
  17999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18004. }
  18005. //2.10====================================== Voltage L3 ====================================================
  18006. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18007. {
  18008. // AC 3 phase L3 volatge
  18009. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18010. {
  18011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18012. {
  18013. tempIndex = 2;
  18014. }
  18015. else
  18016. {
  18017. tempIndex = gun_index;
  18018. }
  18019. for (int index = 0; index < AC_QUANTITY; index++)
  18020. {
  18021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18022. {
  18023. 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
  18024. }
  18025. } // END OF FOR AC_QUANTITY
  18026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18027. }
  18028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18033. }
  18034. //====================== Start SoC ================================
  18035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18036. {
  18037. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18038. 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))
  18039. {
  18040. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18041. {
  18042. tempIndex = ((gun_index==2) ? 1: 0);
  18043. }
  18044. else
  18045. {
  18046. tempIndex = gun_index;
  18047. }
  18048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18049. {
  18050. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18051. {
  18052. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18053. {
  18054. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18055. }
  18056. }
  18057. }
  18058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18059. {
  18060. for (int index = 0; index < CCS_QUANTITY; index++)
  18061. {
  18062. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18063. {
  18064. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18065. }
  18066. }
  18067. }
  18068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18069. {
  18070. for (int index = 0; index < GB_QUANTITY; index++)
  18071. {
  18072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18073. {
  18074. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18075. }
  18076. }
  18077. }
  18078. else if(gunType[gun_index] == GUN_TYPE_DO)
  18079. {
  18080. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18081. {
  18082. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18083. {
  18084. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18085. }
  18086. }
  18087. }
  18088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18094. } // END FOR DC CASE
  18095. }
  18096. //======================================== Message create ==============================================
  18097. json_object *StopTransaction = json_object_new_object();
  18098. json_object *transactionDatas = json_object_new_array();
  18099. json_object *sampledValues = json_object_new_array();
  18100. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18101. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18102. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18103. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18104. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18105. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18106. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18107. {
  18108. json_object *transactionData = json_object_new_object();
  18109. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18110. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18111. {
  18112. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18113. {
  18114. json_object *sampledValue = json_object_new_object();
  18115. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18116. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18117. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18118. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18119. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18120. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18121. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18122. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18123. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18124. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18125. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18126. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18127. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18128. json_object_array_add(sampledValues, sampledValue);
  18129. }
  18130. }
  18131. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18132. json_object_array_add(transactionDatas, transactionData);
  18133. }
  18134. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18135. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18136. ,MESSAGE_TYPE_CALL
  18137. ,guid
  18138. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18139. json_object_put(StopTransaction);
  18140. // Check File "TempStopTransaction" Exist
  18141. if((access(TempStopTransaction,F_OK))!=-1)
  18142. {
  18143. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18144. fclose(fopen(TempStopTransaction, "w"));
  18145. }
  18146. else
  18147. {
  18148. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18149. FILE *log = fopen(TempStopTransaction, "w+");
  18150. if(log == NULL)
  18151. {
  18152. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18153. return ;
  18154. }
  18155. else
  18156. {
  18157. fclose(log);
  18158. }
  18159. }
  18160. //Add TempStopTransaction | Update TempStopTransaction
  18161. // open file for writing
  18162. FILE *outfile;
  18163. outfile = fopen (TempStopTransaction, "a");
  18164. //DEBUG_INFO("data = %s\n", queuedata);
  18165. fputs(queuedata, outfile);
  18166. fputs("\n", outfile);
  18167. fclose (outfile);
  18168. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18169. }
  18170. void checkTempStopTransaction(int gun_index)
  18171. {
  18172. FILE *fptr1;
  18173. char ch;
  18174. char str[QUEUE_MESSAGE_LENGTH]={0};
  18175. char guid[37]={0};
  18176. char tempdata[65]={0};
  18177. char connectorStr[2]={0};
  18178. char TempStopTransaction[256];
  18179. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18180. fptr1 = fopen(TempStopTransaction, "r");
  18181. //TempStopTransaction格式: 槍號,StopTransaction封包
  18182. if (!fptr1)
  18183. {
  18184. //printf(" File not found or unable to open the input file!!\n");
  18185. return ;
  18186. }
  18187. ch=fgetc(fptr1);
  18188. //printf(" Now the content of the file %s is : \n",fname);
  18189. rewind(fptr1);
  18190. if(ch!=EOF)
  18191. {
  18192. // copy all contents to the temporary file except the specific line
  18193. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18194. {
  18195. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18196. if(str[0]=='\0')
  18197. {
  18198. break;
  18199. }
  18200. //TempStopTransaction格式: 槍號,StopTransaction封包
  18201. strncpy(connectorStr, str, 1);
  18202. if(atoi(connectorStr) != (gun_index+1))
  18203. {
  18204. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18205. fclose(fptr1);
  18206. return ;
  18207. }
  18208. //random_uuid(guid);
  18209. strncpy(guid, str+6, 36); //copy guid
  18210. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18211. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18212. {
  18213. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18214. }
  18215. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18216. OCPP_insert_transaction_msg(NO, str);
  18217. memset(str,0,ARRAY_SIZE(str));
  18218. }
  18219. }
  18220. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18221. fclose(fptr1);
  18222. remove(TempStopTransaction); // remove the original file
  18223. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18224. }
  18225. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18226. {
  18227. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18228. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18229. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18230. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18231. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18232. }
  18233. int GetWebSocketPingInterval(void)
  18234. {
  18235. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18236. }
  18237. int GetServerSign(void)
  18238. {
  18239. return server_sign;
  18240. }
  18241. uint8_t GetOcppSecurityProfile()
  18242. {
  18243. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18244. }
  18245. void GetOcppChargerBoxId(uint8_t *data)
  18246. {
  18247. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18248. }
  18249. void GetOcppSecurityPassword(uint8_t *data)
  18250. {
  18251. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18252. }
  18253. void SetOcppVersion(uint8_t *version)
  18254. {
  18255. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18256. DEBUG_INFO("ocpp version: %s\n", version);
  18257. if(strstr((char*)version, "ocpp1.6") != NULL)
  18258. {
  18259. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18260. }
  18261. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18262. {
  18263. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18264. system("pkill OcppBackend");
  18265. }
  18266. }
  18267. void SetServerSign(int value)
  18268. {
  18269. server_sign = value;
  18270. }
  18271. int GetBootNotificationInterval(void)
  18272. {
  18273. return BootNotificationInterval;
  18274. }
  18275. int GetInternetConn(void)
  18276. {
  18277. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18278. }
  18279. int GetBackendConnectionTimeout(void)
  18280. {
  18281. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18282. }
  18283. int isConnectorInitMode(int gun_index)
  18284. {
  18285. int tempIndex = 0;
  18286. int result = TRUE;
  18287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18289. {
  18290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18291. {
  18292. tempIndex = ((gun_index==2) ? 1: 0);
  18293. }
  18294. else
  18295. {
  18296. tempIndex = gun_index;
  18297. }
  18298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18299. {
  18300. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18301. {
  18302. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18303. } //end of the same index
  18304. }//end of for CHAdeMO_QUANTITY
  18305. }
  18306. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18307. {
  18308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18309. {
  18310. tempIndex = ((gun_index==2) ? 1: 0);
  18311. }
  18312. else
  18313. {
  18314. tempIndex = gun_index;
  18315. }
  18316. for (int index = 0; index < CCS_QUANTITY; index++)
  18317. {
  18318. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18319. {
  18320. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18321. } //end of the same index
  18322. } // end of for CCS_QUANTITY
  18323. }
  18324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18325. {
  18326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18327. {
  18328. tempIndex = ((gun_index==2) ? 1: 0);
  18329. }
  18330. else
  18331. {
  18332. tempIndex = gun_index;
  18333. }
  18334. for (int index = 0; index < GB_QUANTITY; index++)
  18335. {
  18336. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18337. {
  18338. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18339. } //end of the same index
  18340. } // end of for GB_QUANTITY
  18341. }
  18342. else if(gunType[gun_index] == GUN_TYPE_DO)
  18343. {
  18344. tempIndex = gun_index;
  18345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18346. {
  18347. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18348. {
  18349. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18350. } //end of the same index
  18351. }
  18352. }
  18353. else
  18354. {
  18355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18356. {
  18357. tempIndex = 2;
  18358. }
  18359. else
  18360. {
  18361. tempIndex = gun_index;
  18362. }
  18363. for (int index = 0; index < AC_QUANTITY; index++)
  18364. {
  18365. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18366. {
  18367. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18368. }//end of the same index
  18369. }//end of for AC_QUANTITY
  18370. }
  18371. return result;
  18372. }
  18373. void refreshProcDogTimer()
  18374. {
  18375. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18376. }
  18377. void InitialSystemValue(void)
  18378. {
  18379. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18380. locallistVersion=0;
  18381. BootNotificationInterval = 0;
  18382. authorizeRetryTimes = 0;
  18383. GunStatusInterval = 10;
  18384. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18385. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18386. //Hear Beat
  18387. HeartBeatWithNOResponse = 0;
  18388. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18389. FirstHeartBeat = 0;
  18390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18391. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18392. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18393. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18394. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18395. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18396. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18397. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18398. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18399. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18400. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18401. //Status && ConnectorPlugIn Setting
  18402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18403. {
  18404. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18405. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18406. }
  18407. for (int index = 0; index < CCS_QUANTITY; index++)
  18408. {
  18409. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18410. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18411. }
  18412. for (int index = 0; index < GB_QUANTITY; index++)
  18413. {
  18414. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18415. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18416. }
  18417. for (int index = 0; index < AC_QUANTITY; index++)
  18418. {
  18419. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18420. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18421. }
  18422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18423. {
  18424. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18425. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18426. }
  18427. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18428. {
  18429. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18430. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18431. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18432. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18433. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18434. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18435. }
  18436. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18437. refreshStartTimer(&clientTime.Heartbeat);
  18438. sleep(1);
  18439. }
  18440. void LWS_Send(char *str)
  18441. {
  18442. //=====================================================
  18443. // Check InternetConn 0: disconnected, 1: connected
  18444. //====================================================
  18445. if(GetOcppConnStatus() == 0)
  18446. {
  18447. DEBUG_INFO("offline now !!!\n");
  18448. return;
  18449. }
  18450. // Only disable isWebsocketSendable operation initiated by charger
  18451. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18452. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18453. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18454. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18455. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18456. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18457. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18458. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18459. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18460. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18461. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18462. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18463. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18464. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18465. {
  18466. isWebsocketSendable = 0;
  18467. }
  18468. pthread_mutex_lock(&lock_send);
  18469. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18470. sprintf((char *)SendBuffer, "%s", str);
  18471. SendBufLen = strlen(str);
  18472. pthread_mutex_unlock(&lock_send);
  18473. lws_callback_on_writable(wsi_client);
  18474. //lws_service(context, 0);
  18475. //sleep(1);
  18476. }
  18477. void LWS_SendNow(char *str)
  18478. {
  18479. //=====================================================
  18480. // Check InternetConn 0: disconnected, 1: connected
  18481. //====================================================
  18482. if(GetOcppConnStatus() == 0)
  18483. {
  18484. DEBUG_INFO("offline now !!!\n");
  18485. return;
  18486. }
  18487. // Only disable isWebsocketSendable operation initiated by charger
  18488. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18489. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18490. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18491. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18492. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18493. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18494. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18495. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18496. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18497. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18498. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18499. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18500. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18501. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18502. {
  18503. isWebsocketSendable = 0;
  18504. }
  18505. pthread_mutex_lock(&lock_send);
  18506. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18507. sprintf((char *)SendBuffer, "%s", str);
  18508. SendBufLen = strlen(str);
  18509. pthread_mutex_unlock(&lock_send);
  18510. lws_callback_on_writable(wsi_client);
  18511. lws_service(context, 0);
  18512. //sleep(1);
  18513. }