MessageHandler.c 888 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077
  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. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //=============================================
  81. // OCPP HeartBeat Response Not Receive Counts
  82. //============================================
  83. static int HeartBeatWithNOResponse = 0;
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. struct timespec Heartbeat;
  100. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  101. struct timespec StartTransaction;
  102. struct timespec StopTransaction;
  103. struct timespec MeterValues[CONNECTOR_QUANTITY];
  104. struct timespec RemoteStartWait;
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  117. unsigned char isOnCharging:1; //bit 4.
  118. unsigned char :3; //bit 5~7
  119. }bits[CONNECTOR_QUANTITY];
  120. }CpinitiateMsg;
  121. CpinitiateMsg cpinitateMsg;
  122. //GetConfiguration Array
  123. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  126. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  127. #if 0
  128. static char *ChargePointErrorCodeStr[] = {
  129. MACROSTR(ConnectorLockFailure),
  130. MACROSTR(EVCommunicationError),
  131. MACROSTR(GroundFailure),
  132. MACROSTR(HighTemperature),
  133. MACROSTR(InternalError),
  134. MACROSTR(LocalListConflict),
  135. MACROSTR(NoError),
  136. MACROSTR(OtherError),
  137. MACROSTR(OverCurrentFailure),
  138. MACROSTR(OverVoltage),
  139. MACROSTR(PowerMeterFailure),
  140. MACROSTR(PowerSwitchFailure),
  141. MACROSTR(ReaderFailure),
  142. MACROSTR(ResetFailure),
  143. MACROSTR(UnderVoltage),
  144. MACROSTR(WeakSignal)
  145. };
  146. #endif
  147. static char * ChargePointStatusStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Preparing),
  150. MACROSTR(Charging),
  151. MACROSTR(SuspendedEVSE),
  152. MACROSTR(SuspendedEV),
  153. MACROSTR(Finishing),
  154. MACROSTR(Reserved),
  155. MACROSTR(Unavailable),
  156. MACROSTR(Faulted)
  157. };
  158. static char *RegistrationStatusStr[] = {
  159. MACROSTR(Accepted),
  160. MACROSTR(Pending),
  161. MACROSTR(Rejected)
  162. };
  163. static char *AvailabilityTypeStr[] = {
  164. MACROSTR(Inoperative),
  165. MACROSTR(Operative)
  166. };
  167. static char *AvailabilityStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Scheduled)
  171. };
  172. static char *ConfigurationStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(RebootRequired),
  176. MACROSTR(NotSupported)
  177. };
  178. static char *ClearCacheStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected)
  181. };
  182. static char *ChargingProfilePurposeTypeStr[] = {
  183. MACROSTR(ChargePointMaxProfile),
  184. MACROSTR(TxDefaultProfile),
  185. MACROSTR(TxProfile)
  186. };
  187. static char *ChargingProfileStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(NotSupported)
  191. };
  192. static char *ClearChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Unknown)
  195. };
  196. static char *GetCompositeScheduleStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected)
  199. };
  200. static char *UpdateTypeStr[] = {
  201. MACROSTR(Differential),
  202. MACROSTR(Full)
  203. };
  204. static char *UpdateStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Failed),
  207. MACROSTR(NotSupported),
  208. MACROSTR(VersionMismatch)
  209. };
  210. static char *RemoteStartStopStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Rejected)
  213. };
  214. static char *ReservationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Faulted),
  217. MACROSTR(Occupied),
  218. MACROSTR(Rejected),
  219. MACROSTR(Unavailable)
  220. };
  221. static char *ResetTypeStr[] = {
  222. MACROSTR(Hard),
  223. MACROSTR(Soft)
  224. };
  225. static char *ResetStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Rejected)
  228. };
  229. static char * DiagnosticsStatusStr[] = {
  230. MACROSTR(Idle),
  231. MACROSTR(Uploaded),
  232. MACROSTR(UploadFailed),
  233. MACROSTR(Uploading)
  234. };
  235. static char * FirmwareStatusStr[] = {
  236. MACROSTR(Downloaded),
  237. MACROSTR(DownloadFailed),
  238. MACROSTR(Downloading),
  239. MACROSTR(Idle),
  240. MACROSTR(InstallationFailed),
  241. MACROSTR(Installing),
  242. MACROSTR(Installed)
  243. };
  244. static char * MessageTriggerStr[] = {
  245. MACROSTR(BootNotification),
  246. MACROSTR(DiagnosticsStatusNotification),
  247. MACROSTR(FirmwareStatusNotification),
  248. MACROSTR(Heartbeat),
  249. MACROSTR(MeterValues),
  250. MACROSTR(StatusNotification)
  251. };
  252. static char * TriggerMessageStatusStr[] = {
  253. MACROSTR(Accepted),
  254. MACROSTR(Rejected),
  255. MACROSTR(NotImplemented)
  256. };
  257. static char * UnlockStatusStr[] = {
  258. MACROSTR(Unlocked),
  259. MACROSTR(UnlockFailed),
  260. MACROSTR(NotSupported)
  261. };
  262. #if 0
  263. static char * StopTransactionReasonStr[] = {
  264. MACROSTR(EmergencyStop),
  265. MACROSTR(EVDisconnected),
  266. MACROSTR(HardReset),
  267. MACROSTR(Local),
  268. MACROSTR(Other),
  269. MACROSTR(PowerLoss),
  270. MACROSTR(Reboot),
  271. MACROSTR(Remote),
  272. MACROSTR(SoftReset),
  273. MACROSTR(UnlockCommand),
  274. MACROSTR(DeAuthorized)
  275. };
  276. #endif
  277. static char * CancelReservationStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected)
  280. };
  281. static char * ReadingContextStr[] = {
  282. MACROSTR(Interruption.Begin),
  283. MACROSTR(Interruption.End),
  284. MACROSTR(Other),
  285. MACROSTR(Sample.Clock),
  286. MACROSTR(Sample.Periodic),
  287. MACROSTR(Transaction.Begin),
  288. MACROSTR(Transaction.End),
  289. MACROSTR(Trigger)
  290. };
  291. static char * ValueFormatStr[] = {
  292. MACROSTR(Raw),
  293. MACROSTR(SignedData)
  294. };
  295. static char * MeasurandStr[] = {
  296. MACROSTR(Current.Export),
  297. MACROSTR(Current.Import),
  298. MACROSTR(Current.Offered),
  299. MACROSTR(Energy.Active.Export.Register),
  300. MACROSTR(Energy.Active.Import.Register),
  301. MACROSTR(Energy.Reactive.Export.Register),
  302. MACROSTR(Energy.Reactive.Import.Register),
  303. MACROSTR(Energy.Active.Export.Interval),
  304. MACROSTR(Energy.Active.Import.Interval),
  305. MACROSTR(Energy.Reactive.Export.Interval),
  306. MACROSTR(Energy.Reactive.Import.Interval),
  307. MACROSTR(Frequency),
  308. MACROSTR(Power.Active.Export),
  309. MACROSTR(Power.Active.Import),
  310. MACROSTR(Power.Factor),
  311. MACROSTR(Power.Offered),
  312. MACROSTR(Power.Reactive.ExportMACROSTR),
  313. MACROSTR(Power.Reactive.Import),
  314. MACROSTR(RPM),
  315. MACROSTR(SoC),
  316. MACROSTR(Temperature),
  317. MACROSTR(Voltage)
  318. };
  319. static char * LocationStr[] = {
  320. MACROSTR(Body),
  321. MACROSTR(Cable),
  322. MACROSTR(EV),
  323. MACROSTR(Inlet),
  324. MACROSTR(Outlet)
  325. };
  326. static char * PhaseStr[] = {
  327. MACROSTR(L1),
  328. MACROSTR(L2),
  329. MACROSTR(L3),
  330. MACROSTR(N),
  331. MACROSTR(L1-N),
  332. MACROSTR(L2-N),
  333. MACROSTR(L3-N),
  334. MACROSTR(L1-L2),
  335. MACROSTR(L2-L3),
  336. MACROSTR(L3-L1)
  337. };
  338. static char * UnitOfMeasureStr[] = {
  339. MACROSTR(Wh),
  340. MACROSTR(kWh),
  341. MACROSTR(varh),
  342. MACROSTR(kvarh),
  343. MACROSTR(W),
  344. MACROSTR(kW),
  345. MACROSTR(VA),
  346. MACROSTR(kVA),
  347. MACROSTR(var),
  348. MACROSTR(kvar),
  349. MACROSTR(A),
  350. MACROSTR(V),
  351. MACROSTR(Celsius),
  352. MACROSTR(Fahrenheit),
  353. MACROSTR(K),
  354. MACROSTR(Percent)
  355. };
  356. //=========================================
  357. // Save configuration
  358. //=========================================
  359. int runShellCmd(const char*cmd)
  360. {
  361. int result = FAIL;
  362. char buf[256];
  363. FILE *fp;
  364. fp = popen(cmd, "r");
  365. if(fp != NULL)
  366. {
  367. while(fgets(buf, sizeof(buf), fp) != NULL)
  368. {
  369. DEBUG_INFO("%s\n", buf);
  370. }
  371. result = PASS;
  372. }
  373. pclose(fp);
  374. return result;
  375. }
  376. int StoreUsrConfigData(struct SysConfigData *UsrData)
  377. {
  378. int result = PASS;
  379. int fd,wrd;
  380. unsigned int i,Chk;
  381. unsigned char *ptr, *BufTmp;
  382. int MtdBlockSize = 0x300000;
  383. Chk=0;
  384. ptr=(unsigned char *)UsrData;
  385. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  386. {
  387. memset(BufTmp,0,MtdBlockSize);
  388. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  389. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  390. Chk+=*(BufTmp+i);
  391. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  392. // Output configuration to file.
  393. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  394. if (fd < 0)
  395. {
  396. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  397. free(BufTmp);
  398. return 0;
  399. }
  400. wrd=write(fd, BufTmp, MtdBlockSize);
  401. close(fd);
  402. if(wrd<MtdBlockSize)
  403. {
  404. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  405. free(BufTmp);
  406. return 0;
  407. }
  408. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  409. DEBUG_INFO("Erase /dev/mtd10.\n");
  410. runShellCmd("flash_erase /dev/mtd10 0 0");
  411. DEBUG_INFO("Write /dev/mtd10.\n");
  412. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  413. DEBUG_INFO("Erase /dev/mtd11.\n");
  414. runShellCmd("flash_erase /dev/mtd11 0 0");
  415. DEBUG_INFO("Write /dev/mtd11.\n");
  416. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  417. system("rm -f /mnt/EvseConfig.bin");
  418. DEBUG_INFO("EvseConfig write to flash OK\n");
  419. }
  420. else
  421. {
  422. DEBUG_ERROR("alloc BlockSize NG\r\n");
  423. result = FAIL;
  424. }
  425. if(BufTmp!=NULL)
  426. free(BufTmp);
  427. return result;
  428. }
  429. //=========================================
  430. // Sqlite3 related function
  431. //=========================================
  432. static int selectSqlCount = 0;
  433. static int callback(void *data, int argc, char **argv, char **azColName){
  434. int i;
  435. //printf("%s: ", (const char*)data);
  436. selectSqlCount = argc;
  437. for(i = 0; i<argc; i++){
  438. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  439. }
  440. //printf("\n");
  441. return 0;
  442. }
  443. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  444. //int i;
  445. //printf("%s:\n", (const char*)data);
  446. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  447. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  448. return 0;
  449. }
  450. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  451. //printf("%s:\n", (const char*)data);
  452. //idTag
  453. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  455. //parentIdTag
  456. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  457. //expir_date
  458. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  459. //status
  460. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  461. //version
  462. if(columenCount > 5)
  463. idTagQuery.listVersionInt = atoi(columnValue[5]);
  464. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  465. return 0;
  466. }
  467. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  468. {
  469. // localversion = argv[5] ? atoi(argv[5]) : 0;
  470. // printf("localversion=%d\n", localversion);
  471. return 0;
  472. }
  473. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  474. {
  475. for (int i = 0; i < n_columns; i++)
  476. {
  477. DEBUG_INFO("%s\t", col_values[i]);
  478. }
  479. DEBUG_INFO("\n");
  480. return 0;
  481. }
  482. int OCPP_cleanLocalCache()
  483. {
  484. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  485. char *errMsg = 0;
  486. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  487. if (SQLITE_OK != rc)
  488. {
  489. DEBUG_INFO("SQL error: %s\n",errMsg);
  490. return FALSE;
  491. }
  492. return TRUE;
  493. }
  494. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  495. {
  496. int isSuccess = TRUE;
  497. int ret = 0;
  498. //const char* data = "Callback function called";
  499. char sql[300];
  500. char zErrMsg[200];
  501. memset(sql, 0, 300);
  502. memset(zErrMsg, 0, 200);
  503. 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);
  504. //* Execute SQL statement */
  505. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  506. if( ret != SQLITE_OK )
  507. {
  508. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  509. isSuccess = FALSE;
  510. }
  511. return isSuccess;
  512. }
  513. void OCPP_getIdTagFromLocalCache(char idTag[])
  514. {
  515. int rc = 0;
  516. char sql[100];
  517. char zErrMsg[100];
  518. memset(sql, 0, 100);
  519. memset(zErrMsg, 0, 100);
  520. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  521. memset(&idTagQuery, 0, sizeof(idTagQuery));
  522. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  523. /* Execute SQL statement */
  524. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  525. if( rc != SQLITE_OK )
  526. {
  527. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  528. }
  529. }
  530. void OCPP_getListVerion()
  531. {
  532. int rc = 0;
  533. // const char* data = "Callback function called";
  534. char sql[100];
  535. char zErrMsg[100];
  536. memset(sql, 0, 100);
  537. memset(zErrMsg, 0, 100);
  538. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  539. /* Execute SQL statement */
  540. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  541. if( rc != SQLITE_OK )
  542. {
  543. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  544. }
  545. }
  546. void OCPP_get_TableAuthlocalAllData(void)
  547. {
  548. int rc = 0;
  549. char sql[100];
  550. char zErrMsg[100];
  551. memset(sql, 0, 100);
  552. memset(zErrMsg, 0, 100);
  553. sprintf(sql,"select * from ocpp_auth_local ");
  554. /* Execute SQL statement */
  555. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  556. if( rc != SQLITE_OK )
  557. {
  558. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  559. }
  560. //return ver;
  561. }
  562. int OCPP_cleanLocalList()
  563. {
  564. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  565. char *errMsg = 0;
  566. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  567. if (SQLITE_OK != rc)
  568. {
  569. DEBUG_INFO("%s\n",errMsg);
  570. return FALSE;
  571. }
  572. return TRUE;
  573. }
  574. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  575. {
  576. int isSuccess = FALSE;
  577. int ret = 0;
  578. //const char* data = "Callback function called";
  579. char sql[300];
  580. char zErrMsg[200];
  581. memset(sql, 0, 300);
  582. memset(zErrMsg, 0, 200);
  583. 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);
  584. //* Execute SQL statement */
  585. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  586. if( ret != SQLITE_OK )
  587. {
  588. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  589. return isSuccess;
  590. }
  591. memset(sql, 0, 300);
  592. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  593. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  594. if( ret != SQLITE_OK )
  595. {
  596. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  597. return isSuccess;
  598. }
  599. isSuccess = TRUE;
  600. return isSuccess;
  601. }
  602. void OCPP_getIdTagFromLocalList(char idTag[])
  603. {
  604. int rc = 0;
  605. // const char* data = "Callback function called";
  606. char sql[100];
  607. char zErrMsg[100];
  608. memset(sql, 0, 100);
  609. memset(zErrMsg, 0, 100);
  610. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  611. memset(&idTagQuery, 0, sizeof(idTagQuery));
  612. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  613. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  614. /* Execute SQL statement */
  615. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  616. if( rc != SQLITE_OK )
  617. {
  618. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  619. }
  620. //return ver;
  621. }
  622. void OCPP_deleteIdTagFromLocalList(char idTag[])
  623. {
  624. //int ver = 0;
  625. //int isSuccess = FALSE;
  626. int rc = 0;
  627. char sql[100];
  628. char zErrMsg[100];
  629. memset(sql, 0, 100);
  630. memset(zErrMsg, 0, 100);
  631. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  632. //* Execute SQL statement */
  633. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  634. if( rc != SQLITE_OK )
  635. {
  636. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  637. }
  638. }
  639. int getCurrentYear()
  640. {
  641. int result = 0;
  642. time_t CurrentTime;
  643. struct tm *tm;
  644. CurrentTime = time(NULL);
  645. tm=localtime(&CurrentTime);
  646. result = (tm->tm_year + 1900);
  647. return result;
  648. }
  649. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  650. {
  651. int result = PASS;
  652. char* errMsg = NULL;
  653. char sqlStr[8192];
  654. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  655. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  656. {
  657. result = FAIL;
  658. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  659. }
  660. 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));
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  665. }
  666. return result;
  667. }
  668. //==========================================
  669. // Check time passed since today
  670. //==========================================
  671. long long DiffTimebWithNow(struct timeb ST)
  672. {
  673. //return milli-second
  674. struct timeb ET;
  675. long long StartTime,StopTime;
  676. ftime(&ET);
  677. StartTime=(long long)ST.time;
  678. StopTime=(long long)ET.time;
  679. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  680. }
  681. int getTimePassSinceToday(uint8_t gun_index)
  682. {
  683. int result = -1;
  684. static time_t lastTime[4];
  685. time_t t;
  686. struct tm *tmStartToday;
  687. struct timeb tbStartToday;
  688. t=time(NULL);
  689. if(difftime(t, lastTime[gun_index])>0)
  690. {
  691. tmStartToday=localtime(&t);
  692. tmStartToday->tm_hour = 0;
  693. tmStartToday->tm_min = 0;
  694. tmStartToday->tm_sec = 0;
  695. tbStartToday.time = mktime(tmStartToday);
  696. tbStartToday.millitm = 0;
  697. result = DiffTimebWithNow(tbStartToday)/1000;
  698. lastTime[gun_index] = t;
  699. }
  700. return result;
  701. }
  702. void getNowDatetime(uint8_t *data)
  703. {
  704. time_t t = time(NULL);
  705. struct tm tm = *localtime(&t);
  706. 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);
  707. }
  708. int syncDateTimeRTC(uint8_t *data)
  709. {
  710. struct ParsingResult
  711. {
  712. int result;
  713. int scanedElement;
  714. int year;
  715. int month;
  716. int mday;
  717. int hour;
  718. int min;
  719. int sec;
  720. int tz_hour;
  721. int tz_min;
  722. float minSec;
  723. }result;
  724. struct tm tmOrg;
  725. struct tm *tmTarget;
  726. struct timeb tbTarget;
  727. char buf[128];
  728. memset(&result, 0x00, sizeof(struct ParsingResult));
  729. result.result = PASS;
  730. if(strstr((char*)data, ".") != NULL)
  731. {
  732. // Original data with mini second
  733. if(strstr((char*)data, "Z") != NULL)
  734. {
  735. // Original data with Z
  736. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  737. &result.year,
  738. &result.month,
  739. &result.mday,
  740. &result.hour,
  741. &result.min,
  742. &result.sec,
  743. &result.minSec);
  744. }
  745. else
  746. {
  747. // Original data without Z
  748. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  749. &result.year,
  750. &result.month,
  751. &result.mday,
  752. &result.hour,
  753. &result.min,
  754. &result.sec,
  755. &result.minSec,
  756. &result.tz_hour,
  757. &result.tz_min);
  758. }
  759. }
  760. else
  761. {
  762. // Original data without mini second
  763. if(strstr((char*)data, "Z") != NULL)
  764. {
  765. // Original data with Z
  766. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  767. &result.year,
  768. &result.month,
  769. &result.mday,
  770. &result.hour,
  771. &result.min,
  772. &result.sec);
  773. }
  774. else
  775. {
  776. // Original data without Z
  777. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  778. &result.year,
  779. &result.month,
  780. &result.mday,
  781. &result.hour,
  782. &result.min,
  783. &result.sec,
  784. &result.tz_hour,
  785. &result.tz_min);
  786. }
  787. }
  788. tmOrg.tm_year = result.year - 1900;
  789. tmOrg.tm_mon = result.month - 1;
  790. tmOrg.tm_mday = result.mday;
  791. tmOrg.tm_hour = result.hour;
  792. tmOrg.tm_min = result.min;
  793. tmOrg.tm_sec = result.sec;
  794. tmOrg.tm_gmtoff = 0;
  795. tbTarget.time = mktime(&tmOrg);
  796. tbTarget.timezone = 0;
  797. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  798. tmTarget = gmtime(&tbTarget.time);
  799. 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);
  800. //DEBUG_INFO(" org date time: %s\n", data);
  801. //DEBUG_INFO("parse date time: %s\n", buf);
  802. system(buf);
  803. system("/sbin/hwclock -w --systohc");
  804. if(result.scanedElement < 6)
  805. result.result = FAIL;
  806. return result.result;
  807. }
  808. //==========================================
  809. // GetCompositeSchedule logic related function
  810. //==========================================
  811. int DiffTimebSec(struct timeb ST, struct timeb ET)
  812. {
  813. //return milli-second
  814. unsigned int StartTime,StopTime;
  815. StartTime=(unsigned int)ST.time;
  816. StopTime=(unsigned int)ET.time;
  817. return (StopTime-StartTime);
  818. }
  819. int DiffTimebWithNowSec(struct timeb ST)
  820. {
  821. //return milli-second
  822. struct timeb ET;
  823. unsigned int StartTime,StopTime;
  824. ftime(&ET);
  825. StartTime=(unsigned int)ST.time;
  826. StopTime=(unsigned int)ET.time;
  827. return (StopTime-StartTime);
  828. }
  829. int getStartStop(uint8_t *start, uint8_t *stop)
  830. {
  831. int result = -1;
  832. struct tm tmStart;
  833. struct timeb tbStart;
  834. struct tm tmStop;
  835. struct timeb tbStop;
  836. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  837. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  838. {
  839. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  840. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  841. tmStart.tm_year -= 1900;
  842. tmStart.tm_mon -= 1;
  843. tbStart.time = mktime(&tmStart);
  844. tbStart.millitm = 0;
  845. tmStop.tm_year -= 1900;
  846. tmStop.tm_mon -= 1;
  847. tbStop.time = mktime(&tmStop);
  848. tbStop.millitm = 0;
  849. result = DiffTimebSec(tbStart, tbStop);
  850. //DEBUG_INFO("getStartStop(): %d\n", result);
  851. }
  852. else
  853. {
  854. DEBUG_WARN("Start or stop date parsing error.\r\n");
  855. }
  856. return result;
  857. }
  858. int isOvertNow(uint8_t *start)
  859. {
  860. int result = NO;
  861. struct ParsingResult
  862. {
  863. int result;
  864. int scanedElement;
  865. int year;
  866. int month;
  867. int mday;
  868. int hour;
  869. int min;
  870. int sec;
  871. int tz_hour;
  872. int tz_min;
  873. float minSec;
  874. }parsingResult;
  875. struct tm tmStart;
  876. struct timeb tbStart;
  877. if(strstr((char*)start, ".") != NULL)
  878. {
  879. // Original data with mini second
  880. if(strstr((char*)start, "Z") != NULL)
  881. {
  882. // Original data with Z
  883. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  884. &parsingResult.year,
  885. &parsingResult.month,
  886. &parsingResult.mday,
  887. &parsingResult.hour,
  888. &parsingResult.min,
  889. &parsingResult.sec,
  890. &parsingResult.minSec);
  891. }
  892. else
  893. {
  894. // Original data without Z
  895. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  896. &parsingResult.year,
  897. &parsingResult.month,
  898. &parsingResult.mday,
  899. &parsingResult.hour,
  900. &parsingResult.min,
  901. &parsingResult.sec,
  902. &parsingResult.minSec,
  903. &parsingResult.tz_hour,
  904. &parsingResult.tz_min);
  905. }
  906. }
  907. else
  908. {
  909. // Original data without mini second
  910. if(strstr((char*)start, "Z") != NULL)
  911. {
  912. // Original data with Z
  913. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  914. &parsingResult.year,
  915. &parsingResult.month,
  916. &parsingResult.mday,
  917. &parsingResult.hour,
  918. &parsingResult.min,
  919. &parsingResult.sec);
  920. }
  921. else
  922. {
  923. // Original data without Z
  924. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  925. &parsingResult.year,
  926. &parsingResult.month,
  927. &parsingResult.mday,
  928. &parsingResult.hour,
  929. &parsingResult.min,
  930. &parsingResult.sec,
  931. &parsingResult.tz_hour,
  932. &parsingResult.tz_min);
  933. }
  934. }
  935. if(parsingResult.scanedElement >= 6)
  936. {
  937. tmStart.tm_year = parsingResult.year - 1900;
  938. tmStart.tm_mon = parsingResult.month - 1;
  939. tmStart.tm_mday = parsingResult.mday;
  940. tmStart.tm_hour = parsingResult.hour;
  941. tmStart.tm_min = parsingResult.min;
  942. tmStart.tm_sec = parsingResult.sec;
  943. tmStart.tm_gmtoff = 0;
  944. tbStart.time = mktime(&tmStart);
  945. tbStart.timezone = 0;
  946. tbStart.millitm = 0;
  947. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  948. if(DiffTimebWithNowSec(tbStart) <= 0)
  949. result = NO;
  950. else
  951. result = YES;
  952. }
  953. else
  954. {
  955. DEBUG_WARN("Start date parsing error.\n");
  956. }
  957. return result;
  958. }
  959. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  960. {
  961. int result = -1;
  962. struct tm tmStart;
  963. struct timeb tbStart;
  964. struct tm tmStop;
  965. struct timeb tbStop;
  966. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  967. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  968. {
  969. tmStart.tm_year -= 1900;
  970. tmStart.tm_mon -= 1;
  971. tbStart.time = mktime(&tmStart);
  972. tbStart.millitm = 0;
  973. tmStop.tm_year -= 1900;
  974. tmStop.tm_mon -= 1;
  975. tbStop.time = mktime(&tmStop);
  976. tbStop.millitm = 0;
  977. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  978. }
  979. return result;
  980. }
  981. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  982. {
  983. FILE *fp;
  984. char profileFileName[128];
  985. char *line = NULL;
  986. size_t len = 0;
  987. time_t CurrentTime;
  988. struct tm *tmComposite;
  989. struct StructChargingProfile maxProfile;
  990. uint8_t limitMax=0;
  991. int compositePeriodIdx = 0;
  992. CurrentTime = time(NULL);
  993. tmComposite=localtime(&CurrentTime);
  994. 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);
  995. if(isUnitA)
  996. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  997. else
  998. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  999. compositeProfile->ChargingSchedule.Duration = durationReq;
  1000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1001. {
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1004. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1005. }
  1006. compositeProfile->ChargingProfileId = 0;
  1007. compositeProfile->StackLevel = 99 ;
  1008. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1009. maxProfile.ChargingProfileId = -1;
  1010. maxProfile.ChargingSchedule.Duration = -1;
  1011. system("rm -f /tmp/*.json");
  1012. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1013. // Search max profile
  1014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1015. if((access(profileFileName, F_OK))!=-1)
  1016. {
  1017. fp = fopen(profileFileName, "r");
  1018. while(getline(&line, &len, fp) != -1)
  1019. {
  1020. json_object *obj = NULL;
  1021. obj = json_tokener_parse(line);
  1022. if(is_error(obj))
  1023. {
  1024. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1025. }
  1026. else
  1027. {
  1028. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1029. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1030. )
  1031. {
  1032. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1033. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1034. )
  1035. {
  1036. struct tm tmFrom, tmTo;
  1037. struct timeb tbFrom, tbTo;
  1038. 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) &&
  1039. (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))
  1040. {
  1041. tmFrom.tm_year -= 1900;
  1042. tmFrom.tm_mon -= 1;
  1043. tbFrom.time = mktime(&tmFrom);
  1044. tmTo.tm_year -= 1900;
  1045. tmTo.tm_mon -= 1;
  1046. tbTo.time = mktime(&tmTo);
  1047. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1048. {
  1049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1050. {
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1054. }
  1055. maxProfile.ChargingProfileId = -1;
  1056. maxProfile.StackLevel = -1;
  1057. if(maxProfile.ChargingProfileId == -1)
  1058. DEBUG_INFO("MaxProfile found.\n");
  1059. else
  1060. DEBUG_INFO("MaxProfile updated.\n");
  1061. // Required item
  1062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1065. if(isUnitA)
  1066. {
  1067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1068. 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++)
  1069. {
  1070. 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"));
  1071. 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?
  1072. 3:
  1073. 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")));
  1074. 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")));
  1075. }
  1076. }
  1077. else
  1078. {
  1079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1080. 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++)
  1081. {
  1082. 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"));
  1083. 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?
  1084. 3:
  1085. 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")));
  1086. 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));
  1087. }
  1088. }
  1089. // Optional item
  1090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1091. {
  1092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1093. }
  1094. else
  1095. {
  1096. sprintf((char*)maxProfile.ValidFrom, " ");
  1097. }
  1098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1099. {
  1100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1101. }
  1102. else
  1103. {
  1104. sprintf((char*)maxProfile.ValidTo, " ");
  1105. }
  1106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1107. {
  1108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1109. }
  1110. else
  1111. {
  1112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1113. }
  1114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1115. {
  1116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1117. }
  1118. else
  1119. {
  1120. maxProfile.TransactionId = -1;
  1121. }
  1122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1123. {
  1124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1125. }
  1126. else
  1127. {
  1128. maxProfile.ChargingSchedule.Duration = 86400;
  1129. }
  1130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1131. {
  1132. 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")));
  1133. }
  1134. else
  1135. {
  1136. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1137. }
  1138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1139. {
  1140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1141. }
  1142. else
  1143. {
  1144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1152. {
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1156. }
  1157. maxProfile.ChargingProfileId = -1;
  1158. maxProfile.StackLevel = -1;
  1159. if(maxProfile.ChargingProfileId == -1)
  1160. DEBUG_INFO("MaxProfile found.\n");
  1161. else
  1162. DEBUG_INFO("MaxProfile updated.\n");
  1163. // Required item
  1164. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1165. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1166. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1167. if(isUnitA)
  1168. {
  1169. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1170. 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++)
  1171. {
  1172. 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"));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. 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")));
  1177. }
  1178. }
  1179. else
  1180. {
  1181. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1182. 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++)
  1183. {
  1184. 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"));
  1185. 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?
  1186. 3:
  1187. 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")));
  1188. 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));
  1189. }
  1190. }
  1191. // Optional item
  1192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1193. {
  1194. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1195. }
  1196. else
  1197. {
  1198. sprintf((char*)maxProfile.ValidFrom, " ");
  1199. }
  1200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1201. {
  1202. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1203. }
  1204. else
  1205. {
  1206. sprintf((char*)maxProfile.ValidTo, " ");
  1207. }
  1208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1209. {
  1210. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1211. }
  1212. else
  1213. {
  1214. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1215. }
  1216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1217. {
  1218. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1219. }
  1220. else
  1221. {
  1222. maxProfile.TransactionId = -1;
  1223. }
  1224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1227. }
  1228. else
  1229. {
  1230. maxProfile.ChargingSchedule.Duration = 86400;
  1231. }
  1232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1233. {
  1234. 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")));
  1235. }
  1236. else
  1237. {
  1238. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1239. }
  1240. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1241. {
  1242. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1243. }
  1244. else
  1245. {
  1246. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. json_object_put(obj);
  1252. }
  1253. fclose(fp);
  1254. /*
  1255. if(maxProfile.ChargingProfileId !=-1)
  1256. {
  1257. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1258. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1259. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1260. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1261. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1262. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1263. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1264. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1265. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1266. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1267. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1271. {
  1272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1275. }
  1276. }
  1277. }
  1278. else
  1279. DEBUG_INFO("MaxProfile not found.\n");
  1280. DEBUG_INFO("------------------------------------\n");*/
  1281. }
  1282. if(maxProfile.ChargingProfileId != -1)
  1283. {
  1284. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1285. {
  1286. if(maxProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1289. 0:
  1290. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1297. 0:
  1298. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1310. {
  1311. if(maxProfile.ChargingSchedule.Duration != -1)
  1312. {
  1313. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1314. }
  1315. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1316. {
  1317. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1318. {
  1319. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1333. {
  1334. if(maxProfile.ChargingSchedule.Duration != -1)
  1335. {
  1336. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1337. 0:
  1338. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1339. }
  1340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1341. {
  1342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1343. {
  1344. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1345. 0:
  1346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1347. if(idxPeriod > 0)
  1348. {
  1349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1350. {
  1351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if(maxProfile.ChargingSchedule.Duration != -1)
  1360. {
  1361. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1362. 0:
  1363. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1364. }
  1365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1370. 0:
  1371. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1372. if(idxPeriod > 0)
  1373. {
  1374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1375. {
  1376. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /*
  1384. DEBUG_INFO("MaxProfile after align.\n");
  1385. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1386. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1387. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1388. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1389. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1390. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1391. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1392. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1393. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1394. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1395. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1397. {
  1398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1399. {
  1400. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1401. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1402. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1403. }
  1404. }
  1405. DEBUG_INFO("------------------------------------\n");*/
  1406. }
  1407. // Find each profile period quantity
  1408. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1409. {
  1410. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1411. limitMax = idx+1;
  1412. }
  1413. if(maxProfile.ChargingProfileId != -1)
  1414. {
  1415. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1416. {
  1417. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1418. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1419. (maxProfile.ChargingSchedule.Duration > 0))
  1420. {
  1421. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1422. {
  1423. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1424. compositePeriodIdx++;
  1425. }
  1426. else
  1427. {
  1428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1429. }
  1430. }
  1431. }
  1432. }
  1433. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1434. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1435. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1436. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1437. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1438. {
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1440. {
  1441. compositeProfile->ChargingProfileId = 1;
  1442. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1443. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1444. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1445. }
  1446. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1447. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1448. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1449. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1450. }
  1451. if(line)
  1452. free(line);
  1453. }
  1454. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1455. {
  1456. FILE *fp;
  1457. char profileFileName[128];
  1458. char *line = NULL;
  1459. size_t len = 0;
  1460. time_t CurrentTime;
  1461. struct tm *tmComposite;
  1462. struct StructChargingProfile maxProfile;
  1463. struct StructChargingProfile defaultTxProfile;
  1464. struct StructChargingProfile txProfile;
  1465. struct StructChargingSchedulePeriod tmpPeriod;
  1466. uint8_t limitMax=0;
  1467. uint8_t limitDef=0;
  1468. uint8_t limitTx=0;
  1469. int compositePeriodIdx = 0;
  1470. CurrentTime = time(NULL);
  1471. tmComposite=localtime(&CurrentTime);
  1472. 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);
  1473. if(isUnitA)
  1474. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1475. else
  1476. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1477. compositeProfile->ChargingSchedule.Duration = durationReq;
  1478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1479. {
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1483. }
  1484. compositeProfile->ChargingProfileId = 0;
  1485. compositeProfile->StackLevel = 99 ;
  1486. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1487. maxProfile.ChargingProfileId = -1;
  1488. defaultTxProfile.ChargingProfileId = -1;
  1489. txProfile.ChargingProfileId = -1;
  1490. maxProfile.ChargingSchedule.Duration = -1;
  1491. defaultTxProfile.ChargingSchedule.Duration = -1;
  1492. txProfile.ChargingSchedule.Duration = -1;
  1493. system("rm -f /tmp/*.json");
  1494. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1495. /*
  1496. * Search valid charging profile
  1497. */
  1498. //DEBUG_INFO("====================================\n");
  1499. // Search tx profile
  1500. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1501. if((access(profileFileName, F_OK))!=-1)
  1502. {
  1503. fp = fopen(profileFileName, "r");
  1504. while(getline(&line, &len, fp) != -1)
  1505. {
  1506. json_object *obj = NULL;
  1507. obj = json_tokener_parse(line);
  1508. if(is_error(obj))
  1509. {
  1510. DEBUG_ERROR("Parse txProfile from file error.\n");
  1511. }
  1512. else
  1513. {
  1514. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1515. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1516. )
  1517. {
  1518. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1519. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1520. )
  1521. {
  1522. struct tm tmFrom, tmTo;
  1523. struct timeb tbFrom, tbTo;
  1524. 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) &&
  1525. (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))
  1526. {
  1527. tmFrom.tm_year -= 1900;
  1528. tmFrom.tm_mon -= 1;
  1529. tbFrom.time = mktime(&tmFrom);
  1530. tmTo.tm_year -= 1900;
  1531. tmTo.tm_mon -= 1;
  1532. tbTo.time = mktime(&tmTo);
  1533. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1534. {
  1535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1536. {
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1540. }
  1541. txProfile.ChargingProfileId = -1;
  1542. txProfile.StackLevel = -1;
  1543. if(txProfile.ChargingProfileId == -1)
  1544. DEBUG_INFO("TxProfile found.\n");
  1545. else
  1546. DEBUG_INFO("TxProfile updated.\n");
  1547. // Required item
  1548. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1549. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1550. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1551. if(isUnitA)
  1552. {
  1553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1554. 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++)
  1555. {
  1556. 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"));
  1557. 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?
  1558. 3:
  1559. 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")));
  1560. 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")));
  1561. }
  1562. }
  1563. else
  1564. {
  1565. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1566. 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++)
  1567. {
  1568. 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"));
  1569. 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?
  1570. 3:
  1571. 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")));
  1572. 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));
  1573. }
  1574. }
  1575. // Optional item
  1576. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1577. {
  1578. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)txProfile.ValidFrom, " ");
  1583. }
  1584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1585. {
  1586. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1587. }
  1588. else
  1589. {
  1590. sprintf((char*)txProfile.ValidTo, " ");
  1591. }
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1593. {
  1594. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)txProfile.RecurrencyKind, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1601. {
  1602. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1603. }
  1604. else
  1605. {
  1606. txProfile.TransactionId = -1;
  1607. }
  1608. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1609. {
  1610. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1611. }
  1612. else
  1613. {
  1614. txProfile.ChargingSchedule.Duration = 86400;
  1615. }
  1616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1617. {
  1618. 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")));
  1619. }
  1620. else
  1621. {
  1622. 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));
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1625. {
  1626. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1627. }
  1628. else
  1629. {
  1630. txProfile.ChargingSchedule.MinChargingRate = -1;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. else
  1636. {
  1637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1642. }
  1643. txProfile.ChargingProfileId = -1;
  1644. txProfile.StackLevel = -1;
  1645. if(txProfile.ChargingProfileId == -1)
  1646. DEBUG_INFO("TxProfile found.\n");
  1647. else
  1648. DEBUG_INFO("TxProfile updated.\n");
  1649. // Required item
  1650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1653. if(isUnitA)
  1654. {
  1655. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1656. 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++)
  1657. {
  1658. 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"));
  1659. 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?
  1660. 3:
  1661. 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")));
  1662. 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")));
  1663. }
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1668. 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++)
  1669. {
  1670. 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"));
  1671. 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?
  1672. 3:
  1673. 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")));
  1674. 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));
  1675. }
  1676. }
  1677. // Optional item
  1678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1679. {
  1680. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1681. }
  1682. else
  1683. {
  1684. sprintf((char*)txProfile.ValidFrom, " ");
  1685. }
  1686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1687. {
  1688. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1689. }
  1690. else
  1691. {
  1692. sprintf((char*)txProfile.ValidTo, " ");
  1693. }
  1694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1695. {
  1696. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1697. }
  1698. else
  1699. {
  1700. sprintf((char*)txProfile.RecurrencyKind, " ");
  1701. }
  1702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1703. {
  1704. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1705. }
  1706. else
  1707. {
  1708. txProfile.TransactionId = -1;
  1709. }
  1710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1711. {
  1712. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1713. }
  1714. else
  1715. {
  1716. txProfile.ChargingSchedule.Duration = 86400;
  1717. }
  1718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1719. {
  1720. 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")));
  1721. }
  1722. else
  1723. {
  1724. 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));
  1725. }
  1726. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1727. {
  1728. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1729. }
  1730. else
  1731. {
  1732. txProfile.ChargingSchedule.MinChargingRate = -1;
  1733. }
  1734. }
  1735. }
  1736. }
  1737. json_object_put(obj);
  1738. }
  1739. fclose(fp);
  1740. /*
  1741. if(txProfile.ChargingProfileId != -1)
  1742. {
  1743. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1744. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1745. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1746. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1747. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1748. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1749. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1750. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1751. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1752. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1753. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1757. {
  1758. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1759. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1760. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1761. }
  1762. }
  1763. }
  1764. else
  1765. DEBUG_INFO("TxProfile not found.\n");*/
  1766. }
  1767. // Search default tx profile
  1768. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1769. if((access(profileFileName, F_OK))==-1)
  1770. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1771. if((access(profileFileName, F_OK))!=-1)
  1772. {
  1773. fp = fopen(profileFileName, "r");
  1774. while(getline(&line, &len, fp) != -1)
  1775. {
  1776. json_object *obj = NULL;
  1777. obj = json_tokener_parse(line);
  1778. if(is_error(obj))
  1779. {
  1780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1781. }
  1782. else
  1783. {
  1784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1786. )
  1787. {
  1788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1790. )
  1791. {
  1792. struct tm tmFrom, tmTo;
  1793. struct timeb tbFrom, tbTo;
  1794. 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) &&
  1795. (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))
  1796. {
  1797. tmFrom.tm_year -= 1900;
  1798. tmFrom.tm_mon -= 1;
  1799. tbFrom.time = mktime(&tmFrom);
  1800. tmTo.tm_year -= 1900;
  1801. tmTo.tm_mon -= 1;
  1802. tbTo.time = mktime(&tmTo);
  1803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1804. {
  1805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1806. {
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1810. }
  1811. defaultTxProfile.ChargingProfileId = -1;
  1812. defaultTxProfile.StackLevel = -1;
  1813. if(defaultTxProfile.ChargingProfileId == -1)
  1814. DEBUG_INFO("TxDefaultProfile found.\n");
  1815. else
  1816. DEBUG_INFO("TxDefaultProfile updated.\n");
  1817. // Required item
  1818. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1819. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1820. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1821. if(isUnitA)
  1822. {
  1823. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1824. 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++)
  1825. {
  1826. 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"));
  1827. 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?
  1828. 3:
  1829. 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")));
  1830. 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")));
  1831. }
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1836. 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++)
  1837. {
  1838. 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"));
  1839. 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?
  1840. 3:
  1841. 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")));
  1842. 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));
  1843. }
  1844. }
  1845. // Optional item
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1847. {
  1848. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1849. }
  1850. else
  1851. {
  1852. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1853. }
  1854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1855. {
  1856. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1857. }
  1858. else
  1859. {
  1860. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1861. }
  1862. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1863. {
  1864. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1865. }
  1866. else
  1867. {
  1868. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1869. }
  1870. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1871. {
  1872. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1873. }
  1874. else
  1875. {
  1876. defaultTxProfile.TransactionId = -1;
  1877. }
  1878. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1879. {
  1880. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1881. }
  1882. else
  1883. {
  1884. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1885. }
  1886. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1887. {
  1888. 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")));
  1889. }
  1890. else
  1891. {
  1892. 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));
  1893. }
  1894. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1895. {
  1896. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1897. }
  1898. else
  1899. {
  1900. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. else
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. defaultTxProfile.ChargingProfileId = -1;
  1914. defaultTxProfile.StackLevel = -1;
  1915. if(defaultTxProfile.ChargingProfileId == -1)
  1916. DEBUG_INFO("TxDefaultProfile found.\n");
  1917. else
  1918. DEBUG_INFO("TxDefaultProfile updated.\n");
  1919. // Required item
  1920. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1921. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1922. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1923. if(isUnitA)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1926. 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++)
  1927. {
  1928. 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"));
  1929. 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?
  1930. 3:
  1931. 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")));
  1932. 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")));
  1933. }
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1938. 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++)
  1939. {
  1940. 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"));
  1941. 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?
  1942. 3:
  1943. 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")));
  1944. 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));
  1945. }
  1946. }
  1947. // Optional item
  1948. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1949. {
  1950. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1951. }
  1952. else
  1953. {
  1954. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1955. }
  1956. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1957. {
  1958. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1963. }
  1964. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1965. {
  1966. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1967. }
  1968. else
  1969. {
  1970. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1971. }
  1972. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1973. {
  1974. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1975. }
  1976. else
  1977. {
  1978. defaultTxProfile.TransactionId = -1;
  1979. }
  1980. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1983. }
  1984. else
  1985. {
  1986. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1987. }
  1988. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1989. {
  1990. 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")));
  1991. }
  1992. else
  1993. {
  1994. 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));
  1995. }
  1996. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1997. {
  1998. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1999. }
  2000. else
  2001. {
  2002. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2003. }
  2004. }
  2005. }
  2006. }
  2007. json_object_put(obj);
  2008. }
  2009. fclose(fp);
  2010. /*
  2011. if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2014. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2015. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2016. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2017. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2018. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2019. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2020. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2021. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2022. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2023. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2025. {
  2026. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2027. {
  2028. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2029. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2030. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2031. }
  2032. }
  2033. }
  2034. else
  2035. DEBUG_INFO("TxDefaultProfile not found.\n");
  2036. DEBUG_INFO("------------------------------------\n");*/
  2037. }
  2038. // Search max profile
  2039. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2040. if((access(profileFileName, F_OK))!=-1)
  2041. {
  2042. fp = fopen(profileFileName, "r");
  2043. while(getline(&line, &len, fp) != -1)
  2044. {
  2045. json_object *obj = NULL;
  2046. obj = json_tokener_parse(line);
  2047. if(is_error(obj))
  2048. {
  2049. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2050. }
  2051. else
  2052. {
  2053. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2054. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2055. )
  2056. {
  2057. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2058. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2059. )
  2060. {
  2061. struct tm tmFrom, tmTo;
  2062. struct timeb tbFrom, tbTo;
  2063. 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) &&
  2064. (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))
  2065. {
  2066. tmFrom.tm_year -= 1900;
  2067. tmFrom.tm_mon -= 1;
  2068. tbFrom.time = mktime(&tmFrom);
  2069. tmTo.tm_year -= 1900;
  2070. tmTo.tm_mon -= 1;
  2071. tbTo.time = mktime(&tmTo);
  2072. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2073. {
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2079. }
  2080. maxProfile.ChargingProfileId = -1;
  2081. maxProfile.StackLevel = -1;
  2082. if(maxProfile.ChargingProfileId == -1)
  2083. DEBUG_INFO("MaxProfile found.\n");
  2084. else
  2085. DEBUG_INFO("MaxProfile updated.\n");
  2086. // Required item
  2087. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2088. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2089. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2090. if(isUnitA)
  2091. {
  2092. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2093. 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++)
  2094. {
  2095. 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"));
  2096. 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?
  2097. 3:
  2098. 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")));
  2099. 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")));
  2100. }
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2105. 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++)
  2106. {
  2107. 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"));
  2108. 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?
  2109. 3:
  2110. 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")));
  2111. 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));
  2112. }
  2113. }
  2114. // Optional item
  2115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2116. {
  2117. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)maxProfile.ValidFrom, " ");
  2122. }
  2123. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2124. {
  2125. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2126. }
  2127. else
  2128. {
  2129. sprintf((char*)maxProfile.ValidTo, " ");
  2130. }
  2131. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2132. {
  2133. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2134. }
  2135. else
  2136. {
  2137. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2138. }
  2139. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2140. {
  2141. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2142. }
  2143. else
  2144. {
  2145. maxProfile.TransactionId = -1;
  2146. }
  2147. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2148. {
  2149. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2150. }
  2151. else
  2152. {
  2153. maxProfile.ChargingSchedule.Duration = 86400;
  2154. }
  2155. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2156. {
  2157. 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")));
  2158. }
  2159. else
  2160. {
  2161. 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));
  2162. }
  2163. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2164. {
  2165. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2166. }
  2167. else
  2168. {
  2169. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2170. }
  2171. }
  2172. }
  2173. }
  2174. else
  2175. {
  2176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2177. {
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2181. }
  2182. maxProfile.ChargingProfileId = -1;
  2183. maxProfile.StackLevel = -1;
  2184. if(maxProfile.ChargingProfileId == -1)
  2185. DEBUG_INFO("MaxProfile found.\n");
  2186. else
  2187. DEBUG_INFO("MaxProfile updated.\n");
  2188. // Required item
  2189. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2190. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2191. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2192. if(isUnitA)
  2193. {
  2194. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2195. 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++)
  2196. {
  2197. 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"));
  2198. 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?
  2199. 3:
  2200. 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")));
  2201. 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")));
  2202. }
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2207. 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++)
  2208. {
  2209. 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"));
  2210. 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?
  2211. 3:
  2212. 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")));
  2213. 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));
  2214. }
  2215. }
  2216. // Optional item
  2217. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2218. {
  2219. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2220. }
  2221. else
  2222. {
  2223. sprintf((char*)maxProfile.ValidFrom, " ");
  2224. }
  2225. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2226. {
  2227. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2228. }
  2229. else
  2230. {
  2231. sprintf((char*)maxProfile.ValidTo, " ");
  2232. }
  2233. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2234. {
  2235. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2236. }
  2237. else
  2238. {
  2239. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2240. }
  2241. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2242. {
  2243. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2244. }
  2245. else
  2246. {
  2247. maxProfile.TransactionId = -1;
  2248. }
  2249. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2250. {
  2251. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2252. }
  2253. else
  2254. {
  2255. maxProfile.ChargingSchedule.Duration = 86400;
  2256. }
  2257. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2258. {
  2259. 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")));
  2260. }
  2261. else
  2262. {
  2263. 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));
  2264. }
  2265. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2266. {
  2267. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2268. }
  2269. else
  2270. {
  2271. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2272. }
  2273. }
  2274. }
  2275. }
  2276. json_object_put(obj);
  2277. }
  2278. fclose(fp);
  2279. /*
  2280. if(maxProfile.ChargingProfileId !=-1)
  2281. {
  2282. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2283. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2284. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2285. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2286. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2287. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2288. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2289. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2290. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2291. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2292. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2298. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2299. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2300. }
  2301. }
  2302. }
  2303. else
  2304. DEBUG_INFO("MaxProfile not found.\n");
  2305. DEBUG_INFO("------------------------------------\n");*/
  2306. }
  2307. /*
  2308. * Align found profile start schedule & periods
  2309. */
  2310. //DEBUG_INFO("====================================\n");
  2311. /*
  2312. // For local test usage, force modify found profile start schedule info
  2313. 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);
  2314. 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);
  2315. 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);
  2316. */
  2317. if(txProfile.ChargingProfileId != -1)
  2318. {
  2319. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2320. {
  2321. if(txProfile.ChargingSchedule.Duration != -1)
  2322. {
  2323. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2324. 0:
  2325. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. }
  2327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2328. {
  2329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2330. {
  2331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2332. 0:
  2333. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2334. if(idxPeriod > 0)
  2335. {
  2336. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2337. {
  2338. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2345. {
  2346. if(txProfile.ChargingSchedule.Duration != -1)
  2347. {
  2348. 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?
  2349. 0:
  2350. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. }
  2352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2353. {
  2354. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2355. {
  2356. 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?
  2357. 0:
  2358. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2359. if(idxPeriod > 0)
  2360. {
  2361. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. else
  2370. {
  2371. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2372. {
  2373. if(txProfile.ChargingSchedule.Duration != -1)
  2374. {
  2375. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2378. }
  2379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2380. {
  2381. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2382. {
  2383. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2384. 0:
  2385. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2386. if(idxPeriod > 0)
  2387. {
  2388. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2389. {
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. else
  2397. {
  2398. if(txProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2401. 0:
  2402. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2409. 0:
  2410. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2411. if(idxPeriod > 0)
  2412. {
  2413. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2414. {
  2415. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. /*
  2423. DEBUG_INFO("txProfile after align.\n");
  2424. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2425. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2426. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2427. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2428. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2429. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2430. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2431. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2432. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2433. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2434. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2436. {
  2437. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2438. {
  2439. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2440. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2441. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2442. }
  2443. }*/
  2444. }
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2448. {
  2449. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2450. {
  2451. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2452. 0:
  2453. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2454. }
  2455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2456. {
  2457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2458. {
  2459. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2460. 0:
  2461. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2463. {
  2464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2465. }
  2466. if(idxPeriod > 0)
  2467. {
  2468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2469. {
  2470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2477. {
  2478. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2479. {
  2480. 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?
  2481. 0:
  2482. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2483. }
  2484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2485. {
  2486. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2487. {
  2488. 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?
  2489. 0:
  2490. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2491. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2492. {
  2493. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2494. }
  2495. if(idxPeriod > 0)
  2496. {
  2497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2498. {
  2499. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. else
  2506. {
  2507. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2508. {
  2509. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2512. 0:
  2513. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2514. }
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2518. {
  2519. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2520. 0:
  2521. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2525. }
  2526. if(idxPeriod > 0)
  2527. {
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. else
  2537. {
  2538. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2539. {
  2540. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2541. 0:
  2542. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2543. }
  2544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2545. {
  2546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2547. {
  2548. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2549. 0:
  2550. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2552. {
  2553. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. }
  2555. if(idxPeriod > 0)
  2556. {
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. /*
  2567. DEBUG_INFO("defaultTxProfile after align.\n");
  2568. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2569. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2570. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2571. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2572. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2573. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2574. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2575. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2576. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2577. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2578. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2582. {
  2583. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2584. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2585. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2586. }
  2587. }
  2588. DEBUG_INFO("------------------------------------\n");*/
  2589. }
  2590. if(maxProfile.ChargingProfileId != -1)
  2591. {
  2592. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2593. {
  2594. if(maxProfile.ChargingSchedule.Duration != -1)
  2595. {
  2596. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. }
  2600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2601. {
  2602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2603. {
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2605. 0:
  2606. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. if(idxPeriod > 0)
  2608. {
  2609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2610. {
  2611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2618. {
  2619. if(maxProfile.ChargingSchedule.Duration != -1)
  2620. {
  2621. 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?
  2622. 0:
  2623. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2624. }
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2628. {
  2629. 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?
  2630. 0:
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2632. if(idxPeriod > 0)
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2635. {
  2636. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. else
  2643. {
  2644. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2645. {
  2646. if(maxProfile.ChargingSchedule.Duration != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2651. }
  2652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2653. {
  2654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2655. {
  2656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2657. 0:
  2658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2659. if(idxPeriod > 0)
  2660. {
  2661. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2662. {
  2663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. else
  2670. {
  2671. if(maxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2674. 0:
  2675. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2682. 0:
  2683. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2684. if(idxPeriod > 0)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2687. {
  2688. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. /*
  2696. DEBUG_INFO("MaxProfile after align.\n");
  2697. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2698. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2699. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2700. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2701. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2702. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2703. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2704. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2705. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2706. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2707. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2709. {
  2710. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2711. {
  2712. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2713. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2714. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2715. }
  2716. }
  2717. DEBUG_INFO("------------------------------------\n");*/
  2718. }
  2719. /*
  2720. * Merge to conposite schedule
  2721. */
  2722. //DEBUG_INFO("====================================\n");
  2723. // Find each profile period quantity
  2724. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2725. {
  2726. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2727. limitMax = idx+1;
  2728. }
  2729. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2732. limitDef = idx+1;
  2733. }
  2734. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2735. {
  2736. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2737. limitTx = idx+1;
  2738. }
  2739. // TxProfile found, composite schedule based on it
  2740. if(txProfile.ChargingProfileId != -1)
  2741. {
  2742. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2743. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2744. {
  2745. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2746. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2747. (txProfile.ChargingSchedule.Duration > 0))
  2748. {
  2749. if(maxProfile.ChargingProfileId != -1)
  2750. {
  2751. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2752. {
  2753. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2754. {
  2755. if((maxProfile.ChargingSchedule.Duration > 0))
  2756. {
  2757. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2758. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2759. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2760. }
  2761. else
  2762. {
  2763. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2764. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2765. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2766. }
  2767. }
  2768. if(idxMaxPeriod == (limitMax-1))
  2769. {
  2770. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2771. {
  2772. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2773. {
  2774. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2775. compositePeriodIdx++;
  2776. }
  2777. else
  2778. {
  2779. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. else
  2786. {
  2787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2788. {
  2789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2790. compositePeriodIdx++;
  2791. }
  2792. else
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2795. }
  2796. }
  2797. }
  2798. if(idxTxPeriod == (limitTx-1))
  2799. {
  2800. if(defaultTxProfile.ChargingProfileId != -1)
  2801. {
  2802. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2803. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2804. {
  2805. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2807. (defaultTxProfile.ChargingSchedule.Duration>0))
  2808. {
  2809. if(maxProfile.ChargingProfileId != -1)
  2810. {
  2811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2814. {
  2815. if((maxProfile.ChargingSchedule.Duration > 0))
  2816. {
  2817. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2818. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2819. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2820. }
  2821. else
  2822. {
  2823. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2825. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2826. }
  2827. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2828. {
  2829. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2830. {
  2831. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2832. compositePeriodIdx++;
  2833. }
  2834. else
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2837. }
  2838. }
  2839. // Delete duplicate period
  2840. if(compositePeriodIdx > 1)
  2841. {
  2842. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2843. {
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2845. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2846. compositePeriodIdx -= 1;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2853. {
  2854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2855. compositePeriodIdx++;
  2856. }
  2857. else
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. }
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2868. {
  2869. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2870. compositePeriodIdx++;
  2871. }
  2872. else
  2873. {
  2874. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2884. else if(defaultTxProfile.ChargingProfileId != -1)
  2885. {
  2886. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2887. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2888. {
  2889. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2890. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2891. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2892. {
  2893. if(maxProfile.ChargingProfileId != -1)
  2894. {
  2895. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2896. {
  2897. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2898. {
  2899. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2900. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2901. if((maxProfile.ChargingSchedule.Duration > 0))
  2902. {
  2903. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2904. }
  2905. else
  2906. {
  2907. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2908. }
  2909. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2910. {
  2911. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2912. {
  2913. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2914. compositePeriodIdx++;
  2915. }
  2916. else
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2919. }
  2920. }
  2921. // Delete duplicate period
  2922. if(compositePeriodIdx > 1)
  2923. {
  2924. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2925. {
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2928. compositePeriodIdx -= 1;
  2929. }
  2930. }
  2931. }
  2932. else
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2935. {
  2936. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2937. compositePeriodIdx++;
  2938. }
  2939. else
  2940. {
  2941. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2942. }
  2943. break;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2950. {
  2951. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2952. compositePeriodIdx++;
  2953. }
  2954. else
  2955. {
  2956. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. // Fill other period by MaxProfile
  2963. if(maxProfile.ChargingProfileId != -1)
  2964. {
  2965. if(compositePeriodIdx==0)
  2966. {
  2967. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2968. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2969. {
  2970. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2971. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2972. (maxProfile.ChargingSchedule.Duration > 0))
  2973. {
  2974. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2975. {
  2976. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2977. compositePeriodIdx++;
  2978. }
  2979. else
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. }
  2983. }
  2984. }
  2985. }
  2986. else
  2987. {
  2988. int lastCompositePeriodIdx = compositePeriodIdx;
  2989. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2990. {
  2991. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2992. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2993. (maxProfile.ChargingSchedule.Duration > 0))
  2994. {
  2995. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2996. {
  2997. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2998. {
  2999. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3000. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3001. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3002. }
  3003. else
  3004. {
  3005. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3006. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3007. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3008. }
  3009. }
  3010. if(tmpPeriod.Limit != -1)
  3011. {
  3012. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3013. {
  3014. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3017. compositePeriodIdx++;
  3018. }
  3019. else
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3022. }
  3023. }
  3024. // Delete duplicate period
  3025. if(compositePeriodIdx > 1)
  3026. {
  3027. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3028. {
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3030. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3031. compositePeriodIdx -= 1;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. compositeProfile->ChargingSchedule.Duration = durationReq;
  3040. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3041. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3042. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3043. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3044. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3045. {
  3046. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3047. {
  3048. compositeProfile->ChargingProfileId = 1;
  3049. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3051. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3052. }
  3053. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3054. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3055. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3056. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3057. }
  3058. if(line)
  3059. free(line);
  3060. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3061. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3062. }
  3063. //==========================================
  3064. // Init all share memory
  3065. //==========================================
  3066. int InitShareMemory()
  3067. {
  3068. int result = PASS;
  3069. int MeterSMId;
  3070. //creat ShmSysConfigAndInfo
  3071. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3072. {
  3073. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3074. result = FAIL;
  3075. }
  3076. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3077. {
  3078. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3079. result = FAIL;
  3080. }
  3081. else
  3082. {}
  3083. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3084. {
  3085. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3086. result = FAIL;
  3087. }
  3088. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3089. {
  3090. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3091. result = FAIL;
  3092. }
  3093. else
  3094. {}
  3095. //creat ShmPsuData
  3096. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3097. {
  3098. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3099. result = FAIL;
  3100. }
  3101. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3102. {
  3103. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3104. result = FAIL;
  3105. }
  3106. else
  3107. {}
  3108. //link ShmOCPP16Data
  3109. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3110. {
  3111. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3112. result = FAIL;
  3113. }
  3114. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3115. {
  3116. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3117. result = FAIL;
  3118. }
  3119. else
  3120. {}
  3121. //creat ShmOCPP16DataPH
  3122. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3123. {
  3124. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3125. result = FAIL;
  3126. }
  3127. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3128. {
  3129. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3130. result = FAIL;
  3131. }
  3132. else
  3133. {}
  3134. /****************************** For Initial Settings************************************************/
  3135. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3136. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3137. // allocate Configuration memory address
  3138. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3141. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3142. //offline MeterValue Interval
  3143. TempMeterValueInterval = 0;
  3144. return result;
  3145. }
  3146. int ProcessShareMemory()
  3147. {
  3148. int result = PASS;
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3163. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3166. ) // 'D' means DC
  3167. {
  3168. // DO series
  3169. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3170. {
  3171. SystemInitial += 1;
  3172. gunTotalNumber += 1;
  3173. gunType[gun_index] = GUN_TYPE_DO;
  3174. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3175. {
  3176. case Gun_Type_Chademo:
  3177. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3178. break;
  3179. case Gun_Type_CCS_2:
  3180. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3181. break;
  3182. case Gun_Type_GB:
  3183. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3184. break;
  3185. case Gun_Type_AC:
  3186. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3187. break;
  3188. default:
  3189. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3190. break;
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3197. {
  3198. SystemInitial += 1;
  3199. gunTotalNumber += 1;
  3200. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3201. {
  3202. case Gun_Type_Chademo:
  3203. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3204. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3205. break;
  3206. case Gun_Type_CCS_2:
  3207. gunType[gun_index] = GUN_TYPE_CCS;
  3208. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3209. break;
  3210. case Gun_Type_GB:
  3211. gunType[gun_index] = GUN_TYPE_GBT;
  3212. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3213. break;
  3214. case Gun_Type_AC:
  3215. gunType[gun_index] = GUN_TYPE_AC;
  3216. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3217. break;
  3218. default:
  3219. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3220. break;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. DEBUG_ERROR("Model name parsing fail.\n");
  3228. result = FAIL;
  3229. }
  3230. if(result != PASS)sleep(5);
  3231. return result;
  3232. }
  3233. void checkRemoteStart(uint8_t connectorIdInt)
  3234. {
  3235. uint8_t tempIndex;
  3236. int result = PASS;
  3237. char cmdBuf[512];
  3238. //check Transaction active
  3239. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3240. {
  3241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3242. {
  3243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3244. }
  3245. else
  3246. {
  3247. tempIndex = connectorIdInt -1;
  3248. }
  3249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3250. {
  3251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3252. {
  3253. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3254. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3255. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3256. {
  3257. //Reserved
  3258. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3259. }
  3260. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3263. {
  3264. //Reserved
  3265. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3266. result = FAIL;
  3267. goto end;
  3268. }
  3269. else
  3270. {
  3271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3272. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3273. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3275. {
  3276. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3277. result = FAIL;
  3278. goto end;
  3279. }
  3280. }//END FOR ELSE
  3281. }
  3282. }// END FOR CHAdeMO_QUANTITY
  3283. }
  3284. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3287. {
  3288. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = connectorIdInt -1;
  3293. }
  3294. for (int index = 0; index < CCS_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3297. {
  3298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3300. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3301. {
  3302. //Reserved
  3303. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3304. }
  3305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3308. {
  3309. //Reserved
  3310. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3311. result = FAIL;
  3312. goto end;
  3313. }
  3314. else
  3315. {
  3316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3320. {
  3321. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3322. result = FAIL;
  3323. goto end;
  3324. }
  3325. }// END FOR ELSE
  3326. }
  3327. }// END FOR CCS_QUANTITY
  3328. }
  3329. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3330. {
  3331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3332. {
  3333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3334. }
  3335. else
  3336. {
  3337. tempIndex = connectorIdInt -1;
  3338. }
  3339. for (int index = 0; index < GB_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3342. {
  3343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3344. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3345. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3346. {
  3347. //Reserved
  3348. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3349. }
  3350. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3353. {
  3354. //Reserved
  3355. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3356. result = FAIL;
  3357. goto end;
  3358. }
  3359. else
  3360. {
  3361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3362. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3363. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3365. {
  3366. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3367. result = FAIL;
  3368. goto end;
  3369. }
  3370. }// END FOR ELSE
  3371. }
  3372. } // END FOR GB_QUANTITY
  3373. }
  3374. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3375. {
  3376. tempIndex = connectorIdInt -1;
  3377. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3380. {
  3381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3382. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3383. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3384. {
  3385. //Reserved
  3386. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3387. }
  3388. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3391. {
  3392. //Reserved
  3393. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3394. result = FAIL;
  3395. goto end;
  3396. }
  3397. else
  3398. {
  3399. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3400. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3401. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3403. {
  3404. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3405. result = FAIL;
  3406. goto end;
  3407. }
  3408. }// END FOR ELSE
  3409. }
  3410. } // END FOR GB_QUANTITY
  3411. }
  3412. else
  3413. {
  3414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3415. {
  3416. tempIndex = 2;
  3417. }
  3418. else
  3419. {
  3420. tempIndex = connectorIdInt -1;
  3421. }
  3422. for (int index = 0; index < AC_QUANTITY; index++)
  3423. {
  3424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3425. {
  3426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3427. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3428. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3429. {
  3430. //Reserved
  3431. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3432. }
  3433. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3436. {
  3437. //Reserved
  3438. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3439. result = FAIL;
  3440. goto end;
  3441. }
  3442. else
  3443. {
  3444. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3445. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3446. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3448. {
  3449. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3450. result = FAIL;
  3451. goto end;
  3452. }
  3453. }//END FOR ELSE
  3454. }
  3455. }// END FOR AC_QUANTITY
  3456. }
  3457. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3458. {
  3459. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3460. {
  3461. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3462. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3463. {
  3464. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3465. system(cmdBuf);
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3471. result = FAIL;
  3472. }
  3473. }
  3474. end:
  3475. if(result == PASS)
  3476. {
  3477. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3478. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3479. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3480. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3482. }
  3483. }
  3484. void CheckSystemValue(void)
  3485. {
  3486. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3487. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3488. char filenmae[100]={0};
  3489. char str[100]={0};
  3490. int tempIndex = 0;
  3491. //===============================
  3492. // send Heartbeat
  3493. //===============================
  3494. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3495. {
  3496. //parameter for test
  3497. sendHeartbeatRequest(0);
  3498. //==============================================
  3499. // Reset Waiting Time
  3500. //==============================================
  3501. HeartBeatWithNOResponse += 2;
  3502. }
  3503. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3504. {
  3505. //==========================================
  3506. // Check remote start without connector id
  3507. //==========================================
  3508. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3509. {
  3510. int connectorIdInt = -1;
  3511. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3512. {
  3513. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3514. {
  3515. connectorIdInt = (gun_index+1);
  3516. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3517. checkRemoteStart(connectorIdInt);
  3518. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3519. break;
  3520. }
  3521. }
  3522. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3523. {
  3524. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3525. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3526. }
  3527. }
  3528. //==========================================
  3529. // csu trigger DataTransferReq
  3530. //==========================================
  3531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3532. {
  3533. sendDataTransferRequest(gun_index);
  3534. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3535. }
  3536. //===============================
  3537. // CSU Trigger Authorize Request
  3538. //===============================
  3539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3540. {
  3541. sendAuthorizeRequest(0);
  3542. authorizeRetryTimes = authorizeRetryTimes + 1;
  3543. if(authorizeRetryTimes < 3)
  3544. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3545. }
  3546. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3547. {
  3548. authorizeRetryTimes = 0;
  3549. SetOcppConnStatus(FALSE);
  3550. server_sign = FALSE;
  3551. }
  3552. 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))
  3553. {
  3554. sendAuthorizeRequest(0);
  3555. }
  3556. //==============================================
  3557. // Charger start transaction
  3558. //==============================================
  3559. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3560. {
  3561. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3562. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3563. sendStartTransactionRequest(gun_index);
  3564. refreshStartTimer(&clientTime.StartTransaction);
  3565. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3566. //storeTempStopTransaction(gun_index);
  3567. }
  3568. //==============================================
  3569. // Charger stop transaction
  3570. //==============================================
  3571. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3572. {
  3573. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3574. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3575. sendStopTransactionRequest(gun_index);
  3576. refreshStartTimer(&clientTime.StopTransaction);
  3577. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3578. }
  3579. //==============================================
  3580. // Charger status report
  3581. //==============================================
  3582. //--- Check Mode Change ---//
  3583. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3599. {
  3600. // Sent unplug message for California pricing logic
  3601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3602. {
  3603. uint8_t ts[20];
  3604. getNowDatetime(ts);
  3605. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3606. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3607. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3608. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3609. }
  3610. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3611. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3613. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3614. {
  3615. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3616. if((access(filenmae,F_OK))!=-1)
  3617. {
  3618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3619. sprintf(str,"rm -f %s",filenmae);
  3620. system(str);
  3621. }
  3622. }
  3623. }
  3624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3625. #if 1 // for TempStopTransaction
  3626. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3627. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3628. {
  3629. checkTempStopTransaction(gun_index);
  3630. }
  3631. #endif
  3632. }
  3633. }
  3634. }
  3635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3636. {
  3637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3638. {
  3639. tempIndex = ((gun_index==2) ? 1: 0);
  3640. }
  3641. else
  3642. {
  3643. tempIndex = gun_index;
  3644. }
  3645. for (int index = 0; index < CCS_QUANTITY; index++)
  3646. {
  3647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3648. {
  3649. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  3650. {
  3651. // Sent unplug message for California pricing logic
  3652. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3653. {
  3654. uint8_t ts[20];
  3655. getNowDatetime(ts);
  3656. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3657. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3658. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3659. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3660. }
  3661. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3662. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3663. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3664. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3665. {
  3666. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3667. if((access(filenmae,F_OK))!=-1)
  3668. {
  3669. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3670. sprintf(str,"rm -f %s",filenmae);
  3671. system(str);
  3672. }
  3673. }
  3674. }
  3675. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3676. #if 1 // for TempStopTransaction
  3677. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3678. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3679. {
  3680. checkTempStopTransaction(gun_index);
  3681. }
  3682. #endif
  3683. }
  3684. }
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < GB_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3699. {
  3700. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3701. {
  3702. // Sent unplug message for California pricing logic
  3703. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3704. {
  3705. uint8_t ts[20];
  3706. getNowDatetime(ts);
  3707. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3711. }
  3712. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3713. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3714. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3715. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3716. {
  3717. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3718. if((access(filenmae,F_OK))!=-1)
  3719. {
  3720. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3721. sprintf(str,"rm -f %s",filenmae);
  3722. system(str);
  3723. }
  3724. }
  3725. }
  3726. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3727. #if 1 // for TempStopTransaction
  3728. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3729. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3730. {
  3731. checkTempStopTransaction(gun_index);
  3732. }
  3733. #endif
  3734. }
  3735. }
  3736. }
  3737. else if(gunType[gun_index] == GUN_TYPE_DO)
  3738. {
  3739. tempIndex = gun_index;
  3740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3743. {
  3744. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3745. {
  3746. // Sent unplug message for California pricing logic
  3747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3748. {
  3749. uint8_t ts[20];
  3750. getNowDatetime(ts);
  3751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3754. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3755. }
  3756. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3757. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3759. 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
  3760. {
  3761. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3762. if((access(filenmae,F_OK))!=-1)
  3763. {
  3764. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3765. sprintf(str,"rm -f %s",filenmae);
  3766. system(str);
  3767. }
  3768. }
  3769. }
  3770. 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);
  3771. #if 1 // for TempStopTransaction
  3772. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3773. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3774. {
  3775. checkTempStopTransaction(gun_index);
  3776. }
  3777. #endif
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3794. {
  3795. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3796. {
  3797. // Sent unplug message for California pricing logic
  3798. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3799. {
  3800. uint8_t ts[20];
  3801. getNowDatetime(ts);
  3802. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3803. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3804. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3805. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3806. }
  3807. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3808. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3809. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3811. {
  3812. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3813. if((access(filenmae,F_OK))!=-1)
  3814. {
  3815. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3816. sprintf(str,"rm -f %s",filenmae);
  3817. system(str);
  3818. }
  3819. }
  3820. }
  3821. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3822. #if 1 // for TempStopTransaction
  3823. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3824. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3825. {
  3826. checkTempStopTransaction(gun_index);
  3827. }
  3828. #endif
  3829. }
  3830. }// END
  3831. }
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3833. (
  3834. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3835. )
  3836. )
  3837. {
  3838. if(SystemInitial > 0)
  3839. SystemInitial -= 1;
  3840. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3841. sendStatusNotificationRequest(gun_index);
  3842. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3843. }
  3844. //==============================================
  3845. // CSU Trigger Smart Charging Profilw
  3846. //==============================================
  3847. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3848. {
  3849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3850. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3851. }
  3852. //==============================================
  3853. // Meter report
  3854. //==============================================
  3855. // Trigger MeterValue
  3856. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3857. {
  3858. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3859. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3860. }
  3861. // ClockAlign MeterValue
  3862. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3863. {
  3864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3865. {
  3866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3867. {
  3868. tempIndex = ((gun_index==2) ? 1: 0);
  3869. }
  3870. else
  3871. {
  3872. tempIndex = gun_index;
  3873. }
  3874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3875. {
  3876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3878. {
  3879. reqClockAlignMeter[gun_index] = 1;
  3880. }
  3881. }// End for CHAdeMO
  3882. }
  3883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3884. {
  3885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3886. {
  3887. tempIndex = ((gun_index==2) ? 1: 0);
  3888. }
  3889. else
  3890. {
  3891. tempIndex = gun_index;
  3892. }
  3893. for (int index = 0; index < CCS_QUANTITY; index++)
  3894. {
  3895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3897. {
  3898. reqClockAlignMeter[gun_index] = 1;
  3899. }
  3900. } // End for CCS
  3901. }
  3902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3905. {
  3906. tempIndex = ((gun_index==2) ? 1: 0);
  3907. }
  3908. else
  3909. {
  3910. tempIndex = gun_index;
  3911. }
  3912. for (int index = 0; index < GB_QUANTITY; index++)
  3913. {
  3914. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3916. {
  3917. reqClockAlignMeter[gun_index] = 1;
  3918. }
  3919. }// End for GB
  3920. }
  3921. else if(gunType[gun_index] == GUN_TYPE_DO)
  3922. {
  3923. tempIndex = gun_index;
  3924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3925. {
  3926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3927. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3928. {
  3929. reqClockAlignMeter[gun_index] = 1;
  3930. }
  3931. }
  3932. }
  3933. else
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3936. {
  3937. tempIndex = 2;
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < AC_QUANTITY; index++)
  3944. {
  3945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3946. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3947. {
  3948. reqClockAlignMeter[gun_index] = 1;
  3949. }
  3950. }//End for AC
  3951. }
  3952. }
  3953. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3954. {
  3955. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3956. reqClockAlignMeter[gun_index] = 0;
  3957. }
  3958. // Sample period MeterValue
  3959. 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))))
  3960. {
  3961. //check Transaction active
  3962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3965. {
  3966. tempIndex = ((gun_index==2) ? 1: 0);
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3976. {
  3977. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3978. {
  3979. reqSampleMeter[gun_index] = 1;
  3980. }
  3981. }
  3982. }// End for CHAdeMO
  3983. }
  3984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3985. {
  3986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3987. {
  3988. tempIndex = ((gun_index==2) ? 1: 0);
  3989. }
  3990. else
  3991. {
  3992. tempIndex = gun_index;
  3993. }
  3994. for (int index = 0; index < CCS_QUANTITY; index++)
  3995. {
  3996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3997. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4000. {
  4001. reqSampleMeter[gun_index] = 1;
  4002. }
  4003. }
  4004. } // End for CCS
  4005. }
  4006. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4007. {
  4008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4009. {
  4010. tempIndex = ((gun_index==2) ? 1: 0);
  4011. }
  4012. else
  4013. {
  4014. tempIndex = gun_index;
  4015. }
  4016. for (int index = 0; index < GB_QUANTITY; index++)
  4017. {
  4018. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4019. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4020. {
  4021. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4022. {
  4023. reqSampleMeter[gun_index] = 1;
  4024. }
  4025. }
  4026. }// End for GB
  4027. }
  4028. else if(gunType[gun_index] == GUN_TYPE_DO)
  4029. {
  4030. tempIndex = gun_index;
  4031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4032. {
  4033. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4034. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4037. {
  4038. reqSampleMeter[gun_index] = 1;
  4039. }
  4040. }
  4041. }
  4042. }
  4043. else
  4044. {
  4045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4046. {
  4047. tempIndex = 2;
  4048. }
  4049. else
  4050. {
  4051. tempIndex = gun_index;
  4052. }
  4053. for (int index = 0; index < AC_QUANTITY; index++)
  4054. {
  4055. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4057. {
  4058. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4059. {
  4060. reqSampleMeter[gun_index] = 1;
  4061. }
  4062. }
  4063. }//End for AC
  4064. }
  4065. if(reqSampleMeter[gun_index] == 1)
  4066. {
  4067. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4068. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4069. //storeTempStopTransaction(gun_index);
  4070. }
  4071. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4072. }
  4073. //==============================================
  4074. // Check Connector reserved
  4075. //==============================================
  4076. //===============================
  4077. // Check if Reserve is expired
  4078. //===============================
  4079. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4080. {
  4081. double diff_t;
  4082. struct tm tp;
  4083. // current time
  4084. time_t t = time(NULL);
  4085. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4086. tp.tm_isdst = -1;
  4087. time_t utc = mktime(&tp);
  4088. diff_t = difftime(utc, t);
  4089. if(diff_t <= 0)
  4090. {
  4091. DEBUG_INFO("reserve expired.\n");
  4092. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4093. }
  4094. }//END OF Check if Reserve is expired
  4095. //==========================================
  4096. // csu trigger FirmwareStatusNotificationReq
  4097. //==========================================
  4098. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4099. {
  4100. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4101. }
  4102. //==========================================
  4103. // csu trigger DiagnosticsStatusNotificationReq
  4104. //==========================================
  4105. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4106. {
  4107. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4108. }
  4109. //==========================================
  4110. // csu trigger CancelReservationConf
  4111. //==========================================
  4112. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4113. {
  4114. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4115. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4116. }
  4117. //==========================================
  4118. // csu trigger ChangeAvailabilityConf
  4119. //==========================================
  4120. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4121. {
  4122. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4123. }
  4124. //==========================================
  4125. // csu trigger UnlockConnectorConf
  4126. //==========================================
  4127. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4128. {
  4129. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4130. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4131. }
  4132. //==========================================
  4133. // csu trigger ReserveNowConf
  4134. //==========================================
  4135. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4136. {
  4137. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4139. }
  4140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4141. {
  4142. sendSignCertificateRequest();
  4143. }
  4144. }
  4145. }
  4146. //==========================================
  4147. // send request routine
  4148. //==========================================
  4149. int sendAuthorizeRequest(int gun_index)
  4150. {
  4151. mtrace();
  4152. int result = FAIL;
  4153. char message[100]={0};
  4154. char guid[37];
  4155. char tempdata[65]={0};
  4156. DEBUG_INFO("sendAuthorizeRequest...\n");
  4157. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4158. //Local Authorize
  4159. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4160. {
  4161. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4162. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4163. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4164. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4165. result = PASS;
  4166. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4167. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4168. authorizeRetryTimes = 0;
  4169. return result;
  4170. }
  4171. 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))||
  4172. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4173. {
  4174. // Query from cache
  4175. DEBUG_INFO("Authorize from cache.\n");
  4176. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4177. // Query from list
  4178. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4179. {
  4180. DEBUG_INFO("Authorize from list.\n");
  4181. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4182. }
  4183. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4184. {
  4185. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4186. {
  4187. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4188. }
  4189. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4190. {
  4191. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4192. }
  4193. if(!GetOcppConnStatus())
  4194. {
  4195. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4196. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4197. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4198. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4199. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4200. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4201. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4202. authorizeRetryTimes = 0;
  4203. return result;
  4204. }
  4205. }
  4206. else
  4207. {
  4208. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4209. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4210. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4211. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4212. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4213. else
  4214. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4215. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4216. result = PASS;
  4217. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4218. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4219. authorizeRetryTimes = 0;
  4220. return result;
  4221. }
  4222. }
  4223. //initialize struct Authorize
  4224. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4225. //get data from shared memory
  4226. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4227. random_uuid(guid);
  4228. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4229. LWS_Send(message);
  4230. sprintf(tempdata, "Authorize,%d", gun_index);
  4231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4232. {
  4233. result = PASS;
  4234. DEBUG_INFO("Authorize mapItem pass\n");
  4235. }
  4236. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4237. return result;
  4238. }
  4239. int sendBootNotificationRequest(void)
  4240. {
  4241. mtrace();
  4242. int result = FAIL;
  4243. char message[500]={0}, payload[700]={0};
  4244. char guid[37]={0};
  4245. char tempdata[65]={0};
  4246. // Fill BootNotification fields
  4247. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4248. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4249. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4250. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4251. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4252. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4253. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4254. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4255. ShmOCPP16DataPH->ChargeBoxId
  4256. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4257. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4258. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4259. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4260. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4261. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4262. random_uuid(guid);
  4263. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4264. LWS_Send(message);
  4265. sprintf(tempdata, "BootNotification,0");
  4266. 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*/)
  4267. {
  4268. result = PASS;
  4269. }
  4270. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4271. strcpy(queuedata,message);
  4272. return result;
  4273. }
  4274. int sendDataTransferRequest(int gun_index)
  4275. {
  4276. mtrace();
  4277. char message[1000]={0};
  4278. char guid[37]={0};
  4279. char tempdata[65]={0};
  4280. int result = FAIL;
  4281. random_uuid(guid);
  4282. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4283. MESSAGE_TYPE_CALL,
  4284. guid,
  4285. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4286. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4287. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4288. LWS_Send(message);
  4289. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4291. {
  4292. result = PASS;
  4293. DEBUG_INFO("DataTransfer mapItem pass\n");
  4294. }
  4295. return result;
  4296. }
  4297. int sendDiagnosticsStatusNotificationRequest(char *status)
  4298. {
  4299. mtrace();
  4300. int result = FAIL;
  4301. char message[110]={0};
  4302. char guid[37]={0};
  4303. char tempdata[65]={0};
  4304. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4305. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4306. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4307. random_uuid(guid);
  4308. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4309. LWS_SendNow(message);
  4310. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4311. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4312. {
  4313. result = PASS;
  4314. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4315. }
  4316. //#ifdef SystemLogMessage
  4317. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4318. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4319. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4320. //#endif
  4321. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4322. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4323. //record status
  4324. if(strcmp(status,"Idle")==0)
  4325. {
  4326. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4327. }
  4328. else if(strcmp(status,"Uploaded")==0)
  4329. {
  4330. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4331. }
  4332. else if(strcmp(status,"UploadFailed")==0)
  4333. {
  4334. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4335. }
  4336. else if(strcmp(status,"Uploading")==0)
  4337. {
  4338. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4339. }
  4340. return result;
  4341. }
  4342. int sendFirmwareStatusNotificationRequest(char *status)
  4343. {
  4344. mtrace();
  4345. int result = FAIL;
  4346. char message[110]={0};
  4347. char guid[37]={0};
  4348. char tempdata[65]={0};
  4349. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4350. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4351. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4352. random_uuid(guid);
  4353. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4354. LWS_SendNow(message);
  4355. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4356. 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*/)
  4357. {
  4358. result = PASS;
  4359. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4360. }
  4361. //#ifdef SystemLogMessage
  4362. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4363. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4364. //#endif
  4365. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4366. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4367. //record status
  4368. if(strcmp(status,"Downloaded")==0)
  4369. {
  4370. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4371. }
  4372. else if(strcmp(status,"DownloadFailed")==0)
  4373. {
  4374. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4375. }
  4376. else if(strcmp(status,"Downloading")==0)
  4377. {
  4378. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4379. }
  4380. else if(strcmp(status,"Idle")==0)
  4381. {
  4382. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4383. }
  4384. else if(strcmp(status,"InstallationFailed")==0)
  4385. {
  4386. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4387. }
  4388. else if(strcmp(status,"Installing")==0)
  4389. {
  4390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4391. }
  4392. else if(strcmp(status,"Installed")==0)
  4393. {
  4394. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4395. }
  4396. return result;
  4397. }
  4398. int sendHeartbeatRequest(int gun_index)
  4399. {
  4400. mtrace();
  4401. int result = FAIL;
  4402. char message[80]={0};
  4403. char guid[37]={0};
  4404. char tempdata[65]={0};
  4405. random_uuid(guid);
  4406. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4407. , MESSAGE_TYPE_CALL
  4408. , guid );
  4409. LWS_Send(message);
  4410. sprintf(tempdata, "Heartbeat,%d", 0);
  4411. 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*/)
  4412. {
  4413. result = PASS;
  4414. }
  4415. return result;
  4416. }
  4417. int sendStartTransactionRequest(int gun_index)
  4418. {
  4419. mtrace();
  4420. int result = FAIL;
  4421. char message[250]={0};
  4422. char guid[37]={0};
  4423. struct timeval tmnow;
  4424. struct tm *tm;
  4425. char buf[28];//, usec_buf[6];
  4426. char tempdata[65]={0};
  4427. int tempIndex = 0;
  4428. DEBUG_INFO("sendStartTransactionRequest...\n");
  4429. gettimeofday(&tmnow, NULL);
  4430. time_t t;
  4431. t = time(NULL);
  4432. /*UTC time and date*/
  4433. tm = gmtime(&t);
  4434. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4435. #if 0 // remove temporally
  4436. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4437. strcat(buf,".");
  4438. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4439. strcat(buf,usec_buf);
  4440. #endif
  4441. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4442. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4443. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4444. // clear StartTransaction Response
  4445. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4446. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4447. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4448. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4449. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4452. {
  4453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4454. {
  4455. tempIndex = ((gun_index==2) ? 1: 0);
  4456. }
  4457. else
  4458. {
  4459. tempIndex = gun_index;
  4460. }
  4461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4462. {
  4463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4464. {
  4465. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4466. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4467. }
  4468. }
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < CCS_QUANTITY; index++)
  4481. {
  4482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4483. {
  4484. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4485. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4486. }
  4487. }
  4488. }
  4489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4492. {
  4493. tempIndex = ((gun_index==2) ? 1: 0);
  4494. }
  4495. else
  4496. {
  4497. tempIndex = gun_index;
  4498. }
  4499. for (int index = 0; index < GB_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4502. {
  4503. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4504. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4505. }
  4506. }
  4507. }
  4508. else if(gunType[gun_index] == GUN_TYPE_DO)
  4509. {
  4510. tempIndex = gun_index;
  4511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4512. {
  4513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4514. {
  4515. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4516. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4517. }
  4518. }
  4519. }
  4520. else
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4523. {
  4524. tempIndex = 2;
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. for (int index = 0; index < AC_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4533. {
  4534. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4535. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4536. }
  4537. }
  4538. }
  4539. random_uuid(guid);
  4540. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4541. {
  4542. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4543. , gun_index +1
  4544. , MESSAGE_TYPE_CALL
  4545. , guid
  4546. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4547. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4548. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4549. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4550. }
  4551. else
  4552. {
  4553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4554. , gun_index +1
  4555. , MESSAGE_TYPE_CALL
  4556. , guid
  4557. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4558. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4559. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4560. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4561. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4562. }
  4563. #if 1
  4564. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4565. 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*/)
  4566. {
  4567. result = PASS;
  4568. }
  4569. #endif
  4570. strcpy(queuedata, message);
  4571. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4572. OCPP_insert_transaction_msg(YES, queuedata);
  4573. return result;
  4574. }
  4575. int sendStatusNotificationRequest(int gun_index)
  4576. {
  4577. mtrace();
  4578. int result = FAIL;
  4579. char message[600]={0};
  4580. char guid[37];
  4581. int currentStatus = 0;
  4582. struct timeval tmnow;
  4583. struct tm *tm;
  4584. char buf[28];//, usec_buf[6];
  4585. char tempdata[65]={0};
  4586. int tempIndex = 0;
  4587. uint8_t isStateChanged = TRUE;
  4588. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4589. gettimeofday(&tmnow, NULL);
  4590. time_t t;
  4591. t = time(NULL);
  4592. /*UTC time and date*/
  4593. tm = gmtime(&t);
  4594. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4595. #if 0 // remove temporally
  4596. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4597. strcat(buf,".");
  4598. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4599. strcat(buf,usec_buf);
  4600. #endif
  4601. //printf("%s",buf);
  4602. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4603. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4604. // it's option
  4605. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4606. /*
  4607. enum _SYSTEM_STATUS
  4608. {
  4609. S_BOOTING = 0,
  4610. S_IDLE, = 1
  4611. S_AUTHORIZING, =2
  4612. S_REASSIGN_CHECK, =3
  4613. S_REASSIGN, =4
  4614. S_PRECHARGE, =5
  4615. S_PREPARING_FOR_EV, =6
  4616. S_PREPARING_FOR_EVSE, =7
  4617. S_CHARGING, =8
  4618. S_TERMINATING, =9
  4619. S_COMPLETE, =10
  4620. S_ALARM, =11
  4621. S_FAULT =12
  4622. }
  4623. */
  4624. //check Transaction active
  4625. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4629. {
  4630. tempIndex = ((gun_index==2) ? 1: 0);
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4637. {
  4638. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4639. {
  4640. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4641. {
  4642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4643. {
  4644. currentStatus = Preparing; //OCPP Status: Preparing
  4645. }
  4646. else
  4647. {
  4648. currentStatus = Available; //OCPP Status: Available
  4649. }
  4650. }
  4651. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4652. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4653. ) //S_PRECHARGE
  4654. {
  4655. currentStatus = Preparing; //OCPP Status: Preparing
  4656. }
  4657. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4658. {
  4659. currentStatus = Charging; //OCPP Status: Charging
  4660. }
  4661. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4662. {
  4663. currentStatus = Finishing; //OCPP Status: Finishing
  4664. }
  4665. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4666. {
  4667. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4668. }
  4669. 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
  4670. {
  4671. currentStatus = Unavailable; //OCPP Status: Unavailable
  4672. }
  4673. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4674. {
  4675. currentStatus = Faulted; //OCPP Status: Faulted
  4676. }
  4677. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4678. {
  4679. currentStatus = Reserved; //OCPP Status: Reserved
  4680. }
  4681. } //end of the same index
  4682. }//end of for CHAdeMO_QUANTITY
  4683. }
  4684. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CCS_QUANTITY; index++)
  4695. {
  4696. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4699. {
  4700. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4701. {
  4702. currentStatus = Preparing; //OCPP Status: Preparing
  4703. }
  4704. else
  4705. {
  4706. currentStatus = Available; //OCPP Status: Available
  4707. }
  4708. }
  4709. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4710. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4711. ) //S_PRECHARGE
  4712. {
  4713. currentStatus = Preparing; //OCPP Status: Preparing
  4714. }
  4715. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4716. {
  4717. currentStatus = Charging; //OCPP Status: Charging
  4718. }
  4719. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4720. {
  4721. currentStatus = Finishing; //OCPP Status: Finishing
  4722. }
  4723. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4724. {
  4725. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4726. }
  4727. 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
  4728. {
  4729. currentStatus = Unavailable; //OCPP Status : Unavailable
  4730. }
  4731. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4732. {
  4733. currentStatus = Faulted; //OCPP Status: Faulted
  4734. }
  4735. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4736. {
  4737. currentStatus = Reserved; //OCPP Status: Reserved
  4738. }
  4739. } //end of the same index
  4740. } // end of for CCS_QUANTITY
  4741. }
  4742. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4745. {
  4746. tempIndex = ((gun_index==2) ? 1: 0);
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < GB_QUANTITY; index++)
  4753. {
  4754. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4755. {
  4756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4757. {
  4758. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4759. {
  4760. currentStatus = Preparing; //OCPP Status: Preparing
  4761. }
  4762. else
  4763. {
  4764. currentStatus = Available; //OCPP Status: Available
  4765. }
  4766. }
  4767. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4768. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4769. ) //S_PRECHARGE
  4770. {
  4771. currentStatus = Preparing; //OCPP Status: Preparing
  4772. }
  4773. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4774. {
  4775. currentStatus = Charging; //OCPP Status: Charging
  4776. }
  4777. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4778. {
  4779. currentStatus = Finishing; //OCPP Status: Finishing
  4780. }
  4781. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4782. {
  4783. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4784. }
  4785. 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
  4786. {
  4787. currentStatus = Unavailable; //OCPP Status: Unavailable
  4788. }
  4789. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4790. {
  4791. currentStatus = Faulted; //OCPP Status: Faulted
  4792. }
  4793. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4794. {
  4795. currentStatus = Reserved; //OCPP Status: Reserved
  4796. }
  4797. } //end of the same index
  4798. } // end of for GB_QUANTITY
  4799. }
  4800. else if(gunType[gun_index] == GUN_TYPE_DO)
  4801. {
  4802. tempIndex = gun_index;
  4803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4804. {
  4805. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4806. {
  4807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4808. {
  4809. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4810. {
  4811. currentStatus = Preparing; //OCPP Status: Preparing
  4812. }
  4813. else
  4814. {
  4815. currentStatus = Available; //OCPP Status: Available
  4816. }
  4817. }
  4818. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4819. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4820. ) //S_PRECHARGE
  4821. {
  4822. currentStatus = Preparing; //OCPP Status: Preparing
  4823. }
  4824. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4825. {
  4826. currentStatus = Charging; //OCPP Status: Charging
  4827. }
  4828. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4829. {
  4830. currentStatus = Finishing; //OCPP Status: Finishing
  4831. }
  4832. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4833. {
  4834. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4835. }
  4836. 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
  4837. {
  4838. currentStatus = Unavailable; //OCPP Status: Unavailable
  4839. }
  4840. 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
  4841. {
  4842. currentStatus = Faulted; //OCPP Status: Faulted
  4843. }
  4844. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4845. {
  4846. currentStatus = Reserved; //OCPP Status: Reserved
  4847. }
  4848. } //end of the same index
  4849. }
  4850. }
  4851. else
  4852. {
  4853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4854. {
  4855. tempIndex = 2;
  4856. }
  4857. else
  4858. {
  4859. tempIndex = gun_index;
  4860. }
  4861. for (int index = 0; index < AC_QUANTITY; index++)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4864. {
  4865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4866. {
  4867. 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))
  4868. {
  4869. currentStatus = Preparing; //OCPP Status: Preparing
  4870. }
  4871. else
  4872. {
  4873. currentStatus = Available; //OCPP Status: Available
  4874. }
  4875. }
  4876. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4877. {
  4878. currentStatus = Preparing; //OCPP Status: Preparing
  4879. }
  4880. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4881. {
  4882. currentStatus = Charging; //OCPP Status: Charging
  4883. }
  4884. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4885. {
  4886. currentStatus = Finishing; //OCPP Status: Finishing
  4887. }
  4888. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4889. {
  4890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4891. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4892. else
  4893. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4894. }
  4895. 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
  4896. {
  4897. currentStatus = Unavailable; //OCPP Status: Unavailable
  4898. }
  4899. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4900. {
  4901. currentStatus = Faulted; //OCPP Status: Faulted
  4902. }
  4903. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4904. {
  4905. currentStatus = Reserved; //OCPP Status: Reserved
  4906. }
  4907. }//end of the same index
  4908. }//end of for AC_QUANTITY
  4909. }
  4910. //it's option
  4911. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4912. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4913. {
  4914. isStateChanged = FALSE;
  4915. }
  4916. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4917. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4918. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4919. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4920. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4921. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4922. random_uuid(guid);
  4923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4924. , MESSAGE_TYPE_CALL
  4925. , guid
  4926. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4927. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4928. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4929. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4930. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4931. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4932. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4933. if((server_sign == TRUE) && isStateChanged)
  4934. {
  4935. LWS_Send(message);
  4936. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4937. 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*/)
  4938. {
  4939. //DEBUG_ERROR("statusNotification mapitem pass");
  4940. result = PASS;
  4941. }
  4942. }
  4943. else
  4944. {
  4945. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4946. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4947. result = PASS;
  4948. }
  4949. return result;
  4950. }
  4951. int sendStopTransactionRequest(int gun_index)
  4952. {
  4953. mtrace();
  4954. int result = FAIL;
  4955. //char message[1500]={0};
  4956. char guid[37]={0};
  4957. char tempdata[65]={0};
  4958. int tempIndex = 0;
  4959. char TempStopTransaction[256];
  4960. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4961. //int idx_sample=0;
  4962. DEBUG_INFO("sendStopTransactionRequest \n");
  4963. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4964. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4965. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4968. {
  4969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4970. {
  4971. tempIndex = ((gun_index==2) ? 1: 0);
  4972. }
  4973. else
  4974. {
  4975. tempIndex = gun_index;
  4976. }
  4977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4978. {
  4979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4980. {
  4981. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4982. }
  4983. }// END OF CHAdeMO_QUANTITY
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < CCS_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5000. }
  5001. }// END OF CCS_QUANTITY
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5004. {
  5005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5006. {
  5007. tempIndex = ((gun_index==2) ? 1: 0);
  5008. }
  5009. else
  5010. {
  5011. tempIndex = gun_index;
  5012. }
  5013. for (int index = 0; index < GB_QUANTITY; index++)
  5014. {
  5015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5016. {
  5017. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5018. }
  5019. }// END OF GB_QUANTITY
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_DO)
  5022. {
  5023. tempIndex = gun_index;
  5024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5027. {
  5028. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5029. }
  5030. }// END OF GB_QUANTITY
  5031. }
  5032. else
  5033. {
  5034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5035. {
  5036. tempIndex = 2;
  5037. }
  5038. else
  5039. {
  5040. tempIndex = gun_index;
  5041. }
  5042. for (int index = 0; index < AC_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5045. {
  5046. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5047. }
  5048. }// END OF AC_QUANTITY
  5049. }
  5050. //====================================== Stop Transaction Time =====================================================
  5051. struct timeval tmnow;
  5052. struct tm *tm;
  5053. char buf[28];//, usec_buf[6];
  5054. gettimeofday(&tmnow, NULL);
  5055. time_t t;
  5056. t = time(NULL);
  5057. /*UTC time and date*/
  5058. tm = gmtime(&t);
  5059. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5061. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5062. random_uuid(guid);
  5063. /***********************************transactionData******************************************************/
  5064. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5066. //=================================
  5067. // Transaction_Begin
  5068. //=================================
  5069. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5070. {
  5071. //============================================ Energy.Active.Import.Interval ================================
  5072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5075. 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*/]);
  5076. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5077. 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))
  5078. {
  5079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5080. }
  5081. else
  5082. {
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5084. }
  5085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5087. }
  5088. //=================================
  5089. // Transaction_End
  5090. //=================================
  5091. // ================================= Current.Import L1 ===============================================
  5092. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5093. {
  5094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5096. {
  5097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5098. {
  5099. tempIndex = ((gun_index==2) ? 1: 0);
  5100. }
  5101. else
  5102. {
  5103. tempIndex = gun_index;
  5104. }
  5105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5108. {
  5109. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5110. }
  5111. }// End of for CHAdeMO_QUANTITY
  5112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5113. }
  5114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5117. {
  5118. tempIndex = ((gun_index==2) ? 1: 0);
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < CCS_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5129. }
  5130. }// End of for CCS_QUANTITY
  5131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5132. }
  5133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5136. {
  5137. tempIndex = ((gun_index==2) ? 1: 0);
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < GB_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5146. {
  5147. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5148. }
  5149. }// End of for GB_QUANTITY
  5150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_DO)
  5153. {
  5154. tempIndex = gun_index;
  5155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5160. }
  5161. }
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5167. {
  5168. tempIndex = 2;
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < AC_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5179. }
  5180. }// End of for AC_QUANTITY
  5181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5182. }
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5188. }
  5189. // ================================= Energy.Active.Import.Interval ==============================================
  5190. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5191. {
  5192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5196. {
  5197. tempIndex = ((gun_index==2) ? 1: 0);
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5206. {
  5207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5208. }
  5209. }// END OF CHAdeMO_QUANTITY
  5210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5211. }
  5212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5213. {
  5214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5215. {
  5216. tempIndex = ((gun_index==2) ? 1: 0);
  5217. }
  5218. else
  5219. {
  5220. tempIndex = gun_index;
  5221. }
  5222. for (int index = 0; index < CCS_QUANTITY; index++)
  5223. {
  5224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5225. {
  5226. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5227. }
  5228. }// END OF CCS_QUANTITY
  5229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5230. }
  5231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5232. {
  5233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5234. {
  5235. tempIndex = ((gun_index==2) ? 1: 0);
  5236. }
  5237. else
  5238. {
  5239. tempIndex = gun_index;
  5240. }
  5241. for (int index = 0; index < GB_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5244. {
  5245. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5246. }
  5247. }// END OF GB_QUANTITY
  5248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5249. }
  5250. else if(gunType[gun_index] == GUN_TYPE_DO)
  5251. {
  5252. tempIndex = gun_index;
  5253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5258. }
  5259. }
  5260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5261. }
  5262. else
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5265. {
  5266. tempIndex = 2;
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < AC_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5275. {
  5276. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5277. }
  5278. }// END OF AC_QUANTITY
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5280. }
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5286. }
  5287. //=================================== Power.Active.Import ==================================================
  5288. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5289. {
  5290. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5292. {
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5294. {
  5295. tempIndex = ((gun_index==2) ? 1: 0);
  5296. }
  5297. else
  5298. {
  5299. tempIndex = gun_index;
  5300. }
  5301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5306. }
  5307. } // End for CHAdeMO_QUANTITY
  5308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5309. }
  5310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5313. {
  5314. tempIndex = ((gun_index==2) ? 1: 0);
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < CCS_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5325. }
  5326. } // END for CCS_QUANTITY
  5327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5328. }
  5329. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5332. {
  5333. tempIndex = ((gun_index==2) ? 1: 0);
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < GB_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5342. {
  5343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5344. }
  5345. }// END for GB_QUANTITY
  5346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5347. }
  5348. else if(gunType[gun_index] == GUN_TYPE_DO)
  5349. {
  5350. tempIndex = gun_index;
  5351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5354. {
  5355. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5356. }
  5357. }
  5358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5359. }
  5360. else
  5361. {
  5362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5363. {
  5364. tempIndex = 2;
  5365. }
  5366. else
  5367. {
  5368. tempIndex = gun_index;
  5369. }
  5370. for (int index = 0; index < AC_QUANTITY; index++)
  5371. {
  5372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5373. {
  5374. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5375. }
  5376. } // END for AC_QUANTITY
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5378. }
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5384. }
  5385. //============================ Voltage L1 ====================================
  5386. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5387. {
  5388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5390. {
  5391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5392. {
  5393. tempIndex = ((gun_index==2) ? 1: 0);
  5394. }
  5395. else
  5396. {
  5397. tempIndex = gun_index;
  5398. }
  5399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5400. {
  5401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5402. {
  5403. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5404. }
  5405. } // END OF FOR CHAdeMO_QUANTITY
  5406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5407. }
  5408. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5411. {
  5412. tempIndex = ((gun_index==2) ? 1: 0);
  5413. }
  5414. else
  5415. {
  5416. tempIndex = gun_index;
  5417. }
  5418. for (int index = 0; index < CCS_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5421. {
  5422. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5423. }
  5424. } // END OF FOR CCS_QUANTITY
  5425. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5428. {
  5429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5430. {
  5431. tempIndex = ((gun_index==2) ? 1: 0);
  5432. }
  5433. else
  5434. {
  5435. tempIndex = gun_index;
  5436. }
  5437. for (int index = 0; index < GB_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5440. {
  5441. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5442. }
  5443. } // END OF FOR GB_QUANTITY
  5444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5445. }
  5446. else if(gunType[gun_index] == GUN_TYPE_DO)
  5447. {
  5448. tempIndex = gun_index;
  5449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5450. {
  5451. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5452. {
  5453. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5454. }
  5455. }
  5456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5457. }
  5458. else
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5461. {
  5462. tempIndex = 2;
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < AC_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5471. {
  5472. 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
  5473. }
  5474. } // END OF FOR AC_QUANTITY
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5482. }
  5483. //====================== End SoC ================================
  5484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5485. {
  5486. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5487. 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))
  5488. {
  5489. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5490. {
  5491. tempIndex = ((gun_index==2) ? 1: 0);
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5504. }
  5505. }
  5506. }
  5507. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5508. {
  5509. for (int index = 0; index < CCS_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5512. {
  5513. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5514. }
  5515. }
  5516. }
  5517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5518. {
  5519. for (int index = 0; index < GB_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5522. {
  5523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5524. }
  5525. }
  5526. }
  5527. else if(gunType[gun_index] == GUN_TYPE_DO)
  5528. {
  5529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5534. }
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5542. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5543. } // END FOR DC CASE
  5544. }
  5545. // ================================= Current.Import L2 ===============================================
  5546. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5547. {
  5548. // AC 3 phse L2 current
  5549. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5552. {
  5553. tempIndex = 2;
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < AC_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5564. }
  5565. }// End of for AC_QUANTITY
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5567. }
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5573. }
  5574. // ================================= Current.Import L3 ===============================================
  5575. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5576. {
  5577. // AC 3 phse L3 current
  5578. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5579. {
  5580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5581. {
  5582. tempIndex = 2;
  5583. }
  5584. else
  5585. {
  5586. tempIndex = gun_index;
  5587. }
  5588. for (int index = 0; index < AC_QUANTITY; index++)
  5589. {
  5590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5591. {
  5592. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5593. }
  5594. }// End of for AC_QUANTITY
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5596. }
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5602. }
  5603. //============================ Voltage L2 ====================================
  5604. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5605. {
  5606. // AC 3 phse L2 voltage
  5607. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5608. {
  5609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5610. {
  5611. tempIndex = 2;
  5612. }
  5613. else
  5614. {
  5615. tempIndex = gun_index;
  5616. }
  5617. for (int index = 0; index < AC_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5620. {
  5621. 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
  5622. }
  5623. } // END OF FOR AC_QUANTITY
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5625. }
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5631. }
  5632. //============================ Voltage L3 ====================================
  5633. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5634. {
  5635. // AC 3 phse L3 voltage
  5636. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5639. {
  5640. tempIndex = 2;
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < AC_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5649. {
  5650. 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
  5651. }
  5652. } // END OF FOR AC_QUANTITY
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5654. }
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5660. }
  5661. //====================== Start SoC ================================
  5662. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5663. {
  5664. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5665. 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))
  5666. {
  5667. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5668. {
  5669. tempIndex = ((gun_index==2) ? 1: 0);
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5676. {
  5677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5682. }
  5683. }
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5686. {
  5687. for (int index = 0; index < CCS_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5692. }
  5693. }
  5694. }
  5695. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5696. {
  5697. for (int index = 0; index < GB_QUANTITY; index++)
  5698. {
  5699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5700. {
  5701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5702. }
  5703. }
  5704. }
  5705. else if(gunType[gun_index] == GUN_TYPE_DO)
  5706. {
  5707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5712. }
  5713. }
  5714. }
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5721. } // END FOR DC CASE
  5722. }
  5723. //================================================ Message create ====================================================
  5724. json_object *StopTransaction = json_object_new_object();
  5725. json_object *transactionDatas = json_object_new_array();
  5726. json_object *sampledValues = json_object_new_array();
  5727. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5728. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5729. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5730. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5731. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5732. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5733. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5734. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5735. {
  5736. json_object *transactionData = json_object_new_object();
  5737. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5738. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5739. {
  5740. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5741. {
  5742. json_object *sampledValue = json_object_new_object();
  5743. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5744. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5745. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5746. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5747. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5749. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5750. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5751. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5752. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5753. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5754. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5755. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5756. json_object_array_add(sampledValues, sampledValue);
  5757. }
  5758. }
  5759. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5760. json_object_array_add(transactionDatas, transactionData);
  5761. }
  5762. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5763. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5764. ,MESSAGE_TYPE_CALL
  5765. ,guid
  5766. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5767. json_object_put(StopTransaction);
  5768. #if 1 // for TempStopTransaction
  5769. //Delete TempStopTransaction
  5770. if((access(TempStopTransaction,F_OK))!=-1)
  5771. {
  5772. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5773. }
  5774. #endif
  5775. #if 1
  5776. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5778. {
  5779. result = PASS;
  5780. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5781. }
  5782. #endif
  5783. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5784. OCPP_insert_transaction_msg(NO, queuedata);
  5785. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5786. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5787. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5788. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5789. {
  5790. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5791. }
  5792. //for test
  5793. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5794. return result;
  5795. }
  5796. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5797. {
  5798. mtrace();
  5799. int result = FAIL;
  5800. char guid[37]={0};
  5801. char tempdata[65]={0};
  5802. int tempIndex = 0;
  5803. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5804. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5805. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5806. //set value
  5807. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5808. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5809. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5810. -1);
  5811. random_uuid(guid);
  5812. //UTC Date time
  5813. struct timeval tmnow;
  5814. struct tm *tm;
  5815. char buf[28];//, usec_buf[6];
  5816. gettimeofday(&tmnow, NULL);
  5817. time_t t;
  5818. t = time(NULL);
  5819. /*UTC time and date*/
  5820. tm = gmtime(&t);
  5821. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5823. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5824. //********************************(1)Current.Import L1************************************************/
  5825. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5826. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5827. (dataType == ReadingContext_Trigger))
  5828. {
  5829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5845. }
  5846. }
  5847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < CCS_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5864. }
  5865. }
  5866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5869. {
  5870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5871. {
  5872. tempIndex = ((gun_index==2) ? 1: 0);
  5873. }
  5874. else
  5875. {
  5876. tempIndex = gun_index;
  5877. }
  5878. for (int index = 0; index < GB_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5886. }
  5887. else if(gunType[gun_index] == GUN_TYPE_DO)
  5888. {
  5889. tempIndex = gun_index;
  5890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5895. }
  5896. }
  5897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5898. }
  5899. else
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5902. {
  5903. tempIndex = 2;
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < AC_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5923. }
  5924. //********************************(2)Energy.Active.Import.Register ************************************************/
  5925. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5926. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5927. (dataType == ReadingContext_Trigger))
  5928. {
  5929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5931. {
  5932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5933. {
  5934. tempIndex = ((gun_index==2) ? 1: 0);
  5935. }
  5936. else
  5937. {
  5938. tempIndex = gun_index;
  5939. }
  5940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5948. }
  5949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < CCS_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5971. {
  5972. tempIndex = ((gun_index==2) ? 1: 0);
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < GB_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_DO)
  5988. {
  5989. tempIndex = gun_index;
  5990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5998. }
  5999. else
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6002. {
  6003. tempIndex = 2;
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < AC_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6017. }
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6023. }
  6024. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6045. }
  6046. } // END OF FOR CHAdeMO_QUANTITY
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < CCS_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6064. }
  6065. } // END OF CCS_QUANTITY
  6066. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < GB_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6083. }
  6084. } // END OF GB_QUANTITY
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_DO)
  6088. {
  6089. tempIndex = gun_index;
  6090. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6098. }
  6099. else
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6102. {
  6103. tempIndex = 2;
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < AC_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6117. }
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6121. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6122. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6123. }
  6124. //********************************(4)Power.Active.Import************************************************/
  6125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6127. (dataType == ReadingContext_Trigger))
  6128. {
  6129. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6130. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6133. {
  6134. tempIndex = ((gun_index==2) ? 1: 0);
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6145. }
  6146. } // END OF FOR
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6148. }
  6149. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < CCS_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6164. }
  6165. }
  6166. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6167. }
  6168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6169. {
  6170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6171. {
  6172. tempIndex = ((gun_index==2) ? 1: 0);
  6173. }
  6174. else
  6175. {
  6176. tempIndex = gun_index;
  6177. }
  6178. for (int index = 0; index < GB_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6181. {
  6182. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6183. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6184. }
  6185. }
  6186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_DO)
  6189. {
  6190. tempIndex = gun_index;
  6191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6194. {
  6195. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6196. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6200. }
  6201. else
  6202. {
  6203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6204. {
  6205. tempIndex = 2;
  6206. }
  6207. else
  6208. {
  6209. tempIndex = gun_index;
  6210. }
  6211. for (int index = 0; index < AC_QUANTITY; index++)
  6212. {
  6213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6214. {
  6215. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6216. }
  6217. }
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6219. }
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6223. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6224. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6225. }
  6226. //***********************************************(5)VOLTAGE L1******************************************************/
  6227. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6228. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6229. (dataType == ReadingContext_Trigger))
  6230. {
  6231. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6232. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6233. {
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6235. {
  6236. tempIndex = ((gun_index==2) ? 1: 0);
  6237. }
  6238. else
  6239. {
  6240. tempIndex = gun_index;
  6241. }
  6242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6245. {
  6246. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6247. }
  6248. }
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6250. }
  6251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6252. {
  6253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6254. {
  6255. tempIndex = ((gun_index==2) ? 1: 0);
  6256. }
  6257. else
  6258. {
  6259. tempIndex = gun_index;
  6260. }
  6261. for (int index = 0; index < CCS_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6264. {
  6265. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6266. }
  6267. }
  6268. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6269. }
  6270. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6271. {
  6272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6273. {
  6274. tempIndex = ((gun_index==2) ? 1: 0);
  6275. }
  6276. else
  6277. {
  6278. tempIndex = gun_index;
  6279. }
  6280. for (int index = 0; index < GB_QUANTITY; index++)
  6281. {
  6282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6283. {
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6285. }
  6286. }
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else if(gunType[gun_index] == GUN_TYPE_DO)
  6290. {
  6291. tempIndex = gun_index;
  6292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else
  6302. {
  6303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6304. {
  6305. tempIndex = 2;
  6306. }
  6307. else
  6308. {
  6309. tempIndex = gun_index;
  6310. }
  6311. for (int index = 0; index < AC_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6316. }
  6317. }
  6318. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6319. }
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6323. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6324. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6325. }
  6326. //***********************************************(6)SOC******************************************************/
  6327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6329. (dataType == ReadingContext_Trigger))
  6330. {
  6331. 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))
  6332. {
  6333. //idx_sample=5;
  6334. //sampledValue = NULL;
  6335. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6344. {
  6345. //tempIndex = ((gun_index==2) ? 1: 0);
  6346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6347. {
  6348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6349. {
  6350. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6351. }
  6352. }
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. //tempIndex = ((gun_index==2) ? 1: 0);
  6357. for (int index = 0; index < CCS_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6360. {
  6361. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6362. }
  6363. }
  6364. }
  6365. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6366. {
  6367. //tempIndex = ((gun_index==2) ? 1: 0);
  6368. for (int index = 0; index < GB_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6373. }
  6374. }
  6375. }
  6376. else if(gunType[gun_index] == GUN_TYPE_DO)
  6377. {
  6378. //tempIndex = ((gun_index==2) ? 1: 0);
  6379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6384. }
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6388. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6390. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6391. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6392. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6393. }
  6394. }
  6395. //********************************(7)Current.Import L2************************************************/
  6396. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6397. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6398. (dataType == ReadingContext_Trigger))
  6399. {
  6400. // Only for AC 3 phase
  6401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6402. {
  6403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6404. {
  6405. tempIndex = 2;
  6406. }
  6407. else
  6408. {
  6409. tempIndex = gun_index;
  6410. }
  6411. for (int index = 0; index < AC_QUANTITY; index++)
  6412. {
  6413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6414. {
  6415. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6416. }
  6417. }
  6418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6419. }
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6425. }
  6426. //********************************(8)Current.Import L3************************************************/
  6427. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6428. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6429. (dataType == ReadingContext_Trigger))
  6430. {
  6431. // Only for AC 3 phase
  6432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6435. {
  6436. tempIndex = 2;
  6437. }
  6438. else
  6439. {
  6440. tempIndex = gun_index;
  6441. }
  6442. for (int index = 0; index < AC_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6447. }
  6448. }
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6450. }
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6456. }
  6457. //***********************************************(9)VOLTAGE L2******************************************************/
  6458. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6459. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6460. (dataType == ReadingContext_Trigger))
  6461. {
  6462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6465. {
  6466. tempIndex = 2;
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < AC_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6480. }
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6486. }
  6487. //***********************************************(10)VOLTAGE L3******************************************************/
  6488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6490. (dataType == ReadingContext_Trigger))
  6491. {
  6492. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6493. {
  6494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6495. {
  6496. tempIndex = 2;
  6497. }
  6498. else
  6499. {
  6500. tempIndex = gun_index;
  6501. }
  6502. for (int index = 0; index < AC_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6507. }
  6508. }
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6516. }
  6517. //***********************************************(11)Current.Offered******************************************************/
  6518. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6519. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6520. (dataType == ReadingContext_Trigger))
  6521. {
  6522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6524. {
  6525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6526. {
  6527. tempIndex = ((gun_index==2) ? 1: 0);
  6528. }
  6529. else
  6530. {
  6531. tempIndex = gun_index;
  6532. }
  6533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6538. }
  6539. } // END OF FOR CHAdeMO_QUANTITY
  6540. }
  6541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6544. {
  6545. tempIndex = ((gun_index==2) ? 1: 0);
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < CCS_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6556. }
  6557. } // END OF CCS_QUANTITY
  6558. }
  6559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6562. {
  6563. tempIndex = ((gun_index==2) ? 1: 0);
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < GB_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6572. {
  6573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6574. }
  6575. } // END OF GB_QUANTITY
  6576. }
  6577. else if(gunType[gun_index] == GUN_TYPE_DO)
  6578. {
  6579. tempIndex = gun_index;
  6580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6581. {
  6582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6583. {
  6584. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6585. }
  6586. }
  6587. }
  6588. else
  6589. {
  6590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6591. {
  6592. tempIndex = 2;
  6593. }
  6594. else
  6595. {
  6596. tempIndex = gun_index;
  6597. }
  6598. for (int index = 0; index < AC_QUANTITY; index++)
  6599. {
  6600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6601. {
  6602. uint16_t currentOffer;
  6603. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6604. {
  6605. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6606. }
  6607. else
  6608. {
  6609. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6610. }
  6611. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6612. }
  6613. }
  6614. }
  6615. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6617. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6618. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6620. }
  6621. //***********************************************(12)Power.Offered******************************************************/
  6622. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6623. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6624. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6625. {
  6626. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6627. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6630. {
  6631. tempIndex = ((gun_index==2) ? 1: 0);
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6640. {
  6641. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6642. }
  6643. } // END OF FOR CHAdeMO_QUANTITY
  6644. }
  6645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6648. {
  6649. tempIndex = ((gun_index==2) ? 1: 0);
  6650. }
  6651. else
  6652. {
  6653. tempIndex = gun_index;
  6654. }
  6655. for (int index = 0; index < CCS_QUANTITY; index++)
  6656. {
  6657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6660. }
  6661. } // END OF CCS_QUANTITY
  6662. }
  6663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6664. {
  6665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6666. {
  6667. tempIndex = ((gun_index==2) ? 1: 0);
  6668. }
  6669. else
  6670. {
  6671. tempIndex = gun_index;
  6672. }
  6673. for (int index = 0; index < GB_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6678. }
  6679. } // END OF GB_QUANTITY
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_DO)
  6682. {
  6683. tempIndex = gun_index;
  6684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6687. {
  6688. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6689. }
  6690. }
  6691. }
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6693. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6694. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6695. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6697. }
  6698. // Message create ====================================================================================================
  6699. if(TRUE)
  6700. {
  6701. json_object *MeterValueReq = json_object_new_object();
  6702. json_object *MeterValues = json_object_new_array();
  6703. json_object *sampledValues = json_object_new_array();
  6704. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6705. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6706. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6707. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6708. {
  6709. json_object *MeterValue = json_object_new_object();
  6710. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6711. {
  6712. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6713. {
  6714. json_object *sampledValue = json_object_new_object();
  6715. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6716. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6717. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6718. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6719. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6720. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6721. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6722. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6723. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6724. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6725. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6726. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6727. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6728. json_object_array_add(sampledValues, sampledValue);
  6729. }
  6730. }
  6731. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6732. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6733. json_object_array_add(MeterValues, MeterValue);
  6734. }
  6735. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6736. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6737. ,gun_index + 1
  6738. ,MESSAGE_TYPE_CALL
  6739. ,guid
  6740. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6741. json_object_put(MeterValueReq);
  6742. }
  6743. // Put request guid to hash map
  6744. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6745. 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*/)
  6746. {
  6747. result = PASS;
  6748. //DEBUG_INFO("MeterValues mapitem pass\n");
  6749. }
  6750. if((dataType != ReadingContext_Trigger) &&
  6751. (dataType != ReadingContext_Sample_Clock) &&
  6752. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6753. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6754. else
  6755. {
  6756. if(FirstHeartBeat)
  6757. LWS_Send(queuedata +2);
  6758. }
  6759. return result;
  6760. }
  6761. int sendLogStatusNotificationRequest(char *status)
  6762. {
  6763. mtrace();
  6764. int result = PASS;
  6765. char message[4096]={0};
  6766. char guid[37]={0};
  6767. char tempdata[128]={0};
  6768. json_object *LogStatusNotification = json_object_new_object();
  6769. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6770. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6771. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6772. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6773. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6774. random_uuid(guid);
  6775. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6776. json_object_put(LogStatusNotification);
  6777. LWS_Send(message);
  6778. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6779. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6780. {
  6781. result = PASS;
  6782. }
  6783. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6784. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6785. return result;
  6786. }
  6787. int sendSecurityEventNotificationRequest()
  6788. {
  6789. mtrace();
  6790. int result = PASS;
  6791. char message[4096]={0};
  6792. char guid[37]={0};
  6793. char tempdata[128]={0};
  6794. json_object *SecurityEventNotification = json_object_new_object();
  6795. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6796. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6797. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6798. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6799. random_uuid(guid);
  6800. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6801. json_object_put(SecurityEventNotification);
  6802. LWS_Send(message);
  6803. sprintf(tempdata, "SecurityEventNotification,0");
  6804. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6805. {
  6806. result = PASS;
  6807. }
  6808. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6809. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6810. return result;
  6811. }
  6812. int sendSignCertificateRequest()
  6813. {
  6814. mtrace();
  6815. int result = PASS;
  6816. char message[4096]={0};
  6817. char guid[37]={0};
  6818. char tempdata[128]={0};
  6819. json_object *SignCertificate = json_object_new_object();
  6820. DEBUG_INFO("sendSignCertificateRequest...\n");
  6821. // Read csr file content
  6822. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6823. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6824. char *line = NULL;
  6825. size_t len = 0;
  6826. while(getline(&line, &len, fp) != -1)
  6827. {
  6828. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6829. {
  6830. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6831. }
  6832. }
  6833. fclose(fp);
  6834. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6835. random_uuid(guid);
  6836. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6837. json_object_put(SignCertificate);
  6838. LWS_Send(message);
  6839. sprintf(tempdata, "SignCertificate,0");
  6840. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6841. {
  6842. result = PASS;
  6843. }
  6844. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6845. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6846. return result;
  6847. }
  6848. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6849. {
  6850. mtrace();
  6851. int result = PASS;
  6852. char message[110]={0};
  6853. char guid[37]={0};
  6854. char tempdata[65]={0};
  6855. json_object *FirmwareStatusNotification = json_object_new_object();
  6856. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6857. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6858. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6859. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6860. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6861. random_uuid(guid);
  6862. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6863. json_object_put(FirmwareStatusNotification);
  6864. LWS_Send(message);
  6865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6866. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6867. {
  6868. result = PASS;
  6869. }
  6870. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6871. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6872. return result;
  6873. }
  6874. //==========================================
  6875. // send confirm routine
  6876. //==========================================
  6877. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. char message[100]={0};
  6882. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6884. LWS_Send(message);
  6885. result = TRUE;
  6886. return result;
  6887. }
  6888. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6889. {
  6890. mtrace();
  6891. int result = FAIL;
  6892. char message[100]={0};
  6893. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6895. LWS_Send(message);
  6896. result = TRUE;
  6897. return result;
  6898. }
  6899. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6900. {
  6901. mtrace();
  6902. int result = FAIL;
  6903. char message[100]={0};
  6904. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6906. LWS_Send(message);
  6907. result = TRUE;
  6908. return result;
  6909. }
  6910. int sendClearCacheConfirmation(char *uuid,char *payload)
  6911. {
  6912. mtrace();
  6913. int result = FAIL;
  6914. char message[500]={0};
  6915. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6916. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6917. LWS_Send(message);
  6918. return result;
  6919. }
  6920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6921. {
  6922. mtrace();
  6923. int result = FAIL;
  6924. char message[500]={0};
  6925. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6926. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6927. LWS_Send(message);
  6928. return result;
  6929. }
  6930. int sendDataTransferConfirmation(char *uuid,char *payload)
  6931. {
  6932. mtrace();
  6933. char statusStr[20]={0};
  6934. char dataStr[10]={0};
  6935. char sstr[20]={0};
  6936. int c = 0;
  6937. char *loc;
  6938. int result = FAIL;
  6939. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6940. /**********************status**************************/
  6941. loc = strstr(payload, "status");
  6942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6943. c = 0;
  6944. while (loc[3+strlen("status")+c] != '\"')
  6945. {
  6946. sstr[c] = loc[3+strlen("status")+c];
  6947. c++;
  6948. }
  6949. sstr[c] = '\0';
  6950. strcpy(statusStr, sstr);
  6951. /**********************data**************************/
  6952. loc = strstr(payload, "data");
  6953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6954. c = 0;
  6955. while (loc[3+strlen("data")+c] != '\"')
  6956. {
  6957. sstr[c] = loc[3+strlen("data")+c];
  6958. c++;
  6959. }
  6960. sstr[c] = '\0';
  6961. strcpy(dataStr, sstr);
  6962. return result;
  6963. }
  6964. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6965. {
  6966. mtrace();
  6967. int result = FAIL;
  6968. char message[1000]={0};
  6969. int CompositeScheduleIndex = 0;
  6970. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6971. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6972. if(nPeriod == 0)
  6973. {
  6974. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6975. {
  6976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6977. ,MESSAGE_TYPE_CALLRESULT
  6978. ,uuid
  6979. ,payload
  6980. ,connectorIdInt);
  6981. }
  6982. else
  6983. {
  6984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,payload
  6988. ,connectorIdInt
  6989. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6990. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6991. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6992. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6993. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6994. }
  6995. }
  6996. else
  6997. {
  6998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6999. ,MESSAGE_TYPE_CALLRESULT
  7000. ,uuid
  7001. ,payload
  7002. ,connectorIdInt
  7003. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7004. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7005. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7006. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7007. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7008. {
  7009. if (idx_sample == 0)
  7010. {
  7011. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7012. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7013. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7014. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7015. }
  7016. else
  7017. {
  7018. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7019. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7020. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7021. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7022. }
  7023. }
  7024. sprintf(message + strlen(message), "]}}]");
  7025. }
  7026. LWS_Send(message);
  7027. result = TRUE;
  7028. return result;
  7029. }
  7030. int sendGetConfigurationConfirmation(char *uuid)
  7031. {
  7032. mtrace();
  7033. int result = FAIL;
  7034. int MaxKeySupported = 0;
  7035. int sentConfigurationNumber= 0;
  7036. int sentunConfigurationNumber= 0;
  7037. char message[1024*10]={0};
  7038. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7039. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7040. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7041. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7042. ,MESSAGE_TYPE_CALLRESULT
  7043. ,uuid );
  7044. //configuration key
  7045. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7046. {
  7047. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7048. {
  7049. if (sentConfigurationNumber == 0)
  7050. {
  7051. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7052. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7053. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7054. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7055. }
  7056. else
  7057. {
  7058. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7059. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7060. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7061. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7062. }
  7063. sentConfigurationNumber = sentConfigurationNumber + 1;
  7064. }
  7065. }
  7066. sprintf(message + strlen(message), "]");
  7067. if(UnknownKeynum != 0)
  7068. {
  7069. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7070. //unkown key
  7071. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7072. {
  7073. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7074. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7075. if(sentunConfigurationNumber == 0)
  7076. {
  7077. sprintf(message + strlen(message), "\"%s\""
  7078. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7079. }
  7080. else
  7081. {
  7082. sprintf(message + strlen(message), ",\"%s\""
  7083. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7084. }
  7085. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7086. }
  7087. sprintf(message + strlen(message), "]");
  7088. }
  7089. sprintf(message + strlen(message), "}]");
  7090. LWS_Send(message);
  7091. return result;
  7092. }
  7093. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7094. {
  7095. mtrace();
  7096. int result = FAIL;
  7097. char message[400]={0};
  7098. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7099. if(strcmp(payload,"")==0)
  7100. {
  7101. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7102. }
  7103. else
  7104. {
  7105. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7106. }
  7107. LWS_Send(message);
  7108. result = TRUE;
  7109. return result;
  7110. }
  7111. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7112. {
  7113. mtrace();
  7114. int result = FAIL;
  7115. char message[80]={0};
  7116. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7117. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7118. LWS_Send(message);
  7119. result = TRUE;
  7120. return result;
  7121. }
  7122. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7123. {
  7124. mtrace();
  7125. int result = FAIL;
  7126. char message[80]={0};
  7127. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7128. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7129. LWS_Send(message);
  7130. result = TRUE;
  7131. return result;
  7132. }
  7133. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7134. {
  7135. mtrace();
  7136. int result = FAIL;
  7137. char message[80]={0};
  7138. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7139. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7140. LWS_Send(message);
  7141. result = TRUE;
  7142. return result;
  7143. }
  7144. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7145. {
  7146. mtrace();
  7147. int result = FAIL;
  7148. char message[80]={0};
  7149. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7150. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7151. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7152. LWS_Send(message);
  7153. result = TRUE;
  7154. return result;
  7155. }
  7156. int sendResetConfirmation(char *uuid,char *payload)
  7157. {
  7158. mtrace();
  7159. int result = FAIL;
  7160. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7161. char message[80]={0};
  7162. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7163. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7164. LWS_Send(message);
  7165. result = TRUE;
  7166. return result;
  7167. }
  7168. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7169. {
  7170. mtrace();
  7171. int result = FAIL;
  7172. char message[500]={0};
  7173. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7174. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7175. LWS_Send(message);
  7176. result = TRUE;
  7177. return result;
  7178. }
  7179. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7184. char message[80]={0};
  7185. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7186. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7187. LWS_Send(message);
  7188. result = TRUE;
  7189. return result;
  7190. }
  7191. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7192. {
  7193. mtrace();
  7194. int result = FAIL;
  7195. char message[80]={0};
  7196. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7197. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7198. LWS_Send(message);
  7199. result = TRUE;
  7200. return result;
  7201. }
  7202. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7203. {
  7204. mtrace();
  7205. int result = FAIL;
  7206. char message[80]={0};
  7207. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7208. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendUpdateFirmwareConfirmation(char *uuid)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[60]={0};
  7219. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7220. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7221. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7222. LWS_Send(message);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. int sendCertificateSignedConfirmation(char *uuid)
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. json_object *CertificateSigned = json_object_new_object();
  7232. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7233. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7234. sprintf(message,"[%d,\"%s\",%s]"
  7235. ,MESSAGE_TYPE_CALLRESULT
  7236. ,uuid
  7237. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7238. json_object_put(CertificateSigned);
  7239. LWS_Send(message);
  7240. return result;
  7241. }
  7242. int sendDeleteCertificateConfirmation(char *uuid)
  7243. {
  7244. mtrace();
  7245. int result = PASS;
  7246. char message[4096]={0};
  7247. json_object *DeleteCertificate = json_object_new_object();
  7248. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7249. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7250. sprintf(message,"[%d,\"%s\",%s]"
  7251. ,MESSAGE_TYPE_CALLRESULT
  7252. ,uuid
  7253. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7254. json_object_put(DeleteCertificate);
  7255. LWS_Send(message);
  7256. return result;
  7257. }
  7258. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7259. {
  7260. mtrace();
  7261. int result = PASS;
  7262. char message[4096]={0};
  7263. json_object *ExtendedTriggerMessage = json_object_new_object();
  7264. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7265. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7266. sprintf(message,"[%d,\"%s\",%s]"
  7267. ,MESSAGE_TYPE_CALLRESULT
  7268. ,uuid
  7269. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7270. json_object_put(ExtendedTriggerMessage);
  7271. LWS_Send(message);
  7272. return result;
  7273. }
  7274. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7275. {
  7276. mtrace();
  7277. int result = PASS;
  7278. char message[4096]={0};
  7279. json_object *GetInstalledCertificateIds = json_object_new_object();
  7280. json_object *certificateHashDataDatas = json_object_new_array();
  7281. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7282. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7283. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7284. {
  7285. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7286. {
  7287. json_object *certificateHashData = json_object_new_object();
  7288. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7289. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7290. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7291. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7292. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7293. }
  7294. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7295. }
  7296. else
  7297. {
  7298. json_object_put(certificateHashDataDatas);
  7299. }
  7300. sprintf(message,"[%d,\"%s\",%s]"
  7301. ,MESSAGE_TYPE_CALLRESULT
  7302. ,uuid
  7303. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7304. json_object_put(GetInstalledCertificateIds);
  7305. LWS_Send(message);
  7306. return result;
  7307. }
  7308. int sendGetLogConfirmation(char *uuid)
  7309. {
  7310. mtrace();
  7311. int result = PASS;
  7312. char message[4096]={0};
  7313. json_object *GetLog = json_object_new_object();
  7314. DEBUG_INFO("sendGetLogConfirmation...\n");
  7315. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7316. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7317. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7318. sprintf(message,"[%d,\"%s\",%s]"
  7319. ,MESSAGE_TYPE_CALLRESULT
  7320. ,uuid
  7321. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(GetLog);
  7323. LWS_Send(message);
  7324. return result;
  7325. }
  7326. int sendInstallCertificateConfirmation(char *uuid)
  7327. {
  7328. mtrace();
  7329. int result = PASS;
  7330. char message[4096]={0};
  7331. json_object *InstallCertificate = json_object_new_object();
  7332. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7333. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7334. sprintf(message,"[%d,\"%s\",%s]"
  7335. ,MESSAGE_TYPE_CALLRESULT
  7336. ,uuid
  7337. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7338. json_object_put(InstallCertificate);
  7339. LWS_Send(message);
  7340. return result;
  7341. }
  7342. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7343. {
  7344. mtrace();
  7345. int result = PASS;
  7346. char message[4096]={0};
  7347. json_object *SignedUpdateFirmware = json_object_new_object();
  7348. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7349. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7350. sprintf(message,"[%d,\"%s\",%s]"
  7351. ,MESSAGE_TYPE_CALLRESULT
  7352. ,uuid
  7353. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7354. json_object_put(SignedUpdateFirmware);
  7355. LWS_Send(message);
  7356. return result;
  7357. }
  7358. int sendUnknownConfirmation(char *uuid)
  7359. {
  7360. mtrace();
  7361. int result = PASS;
  7362. char message[256]={0};
  7363. DEBUG_INFO("sendUnknownConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7365. LWS_Send(message);
  7366. return result;
  7367. }
  7368. //==========================================
  7369. // Handle server request routine Start
  7370. //==========================================
  7371. int handleCancelReservationRequest(char *uuid, char *payload)
  7372. {
  7373. mtrace();
  7374. int result = FAIL;
  7375. int gunNO = 0;
  7376. int reservationIdInt = -1;
  7377. char comfirmstr[20];
  7378. DEBUG_INFO("handleCancelReservationRequest...\n");
  7379. json_object *CancelReservation;
  7380. CancelReservation = json_tokener_parse(payload);
  7381. if(!is_error(CancelReservation))
  7382. {
  7383. // Required data
  7384. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7385. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7386. }
  7387. json_object_put(CancelReservation);
  7388. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7389. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7390. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7391. if(reservationIdInt != -1)
  7392. {
  7393. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7394. //check Transaction active
  7395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7399. {
  7400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7401. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7402. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7403. {
  7404. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7405. }
  7406. else
  7407. {
  7408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7409. }
  7410. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7411. goto end;
  7412. }
  7413. }
  7414. for (int index = 0; index < CCS_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7417. {
  7418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7419. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7420. if(gunType[2] == GUN_TYPE_CCS)
  7421. {
  7422. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7423. }
  7424. else
  7425. {
  7426. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7427. }
  7428. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7429. goto end;
  7430. }
  7431. }
  7432. for (int index = 0; index < GB_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7435. {
  7436. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7437. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7438. if(gunType[2] == GUN_TYPE_GBT)
  7439. {
  7440. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7441. }
  7442. else
  7443. {
  7444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7445. }
  7446. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7447. goto end;
  7448. }
  7449. }
  7450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7451. {
  7452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7453. {
  7454. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7455. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7456. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7457. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7458. goto end;
  7459. }
  7460. }
  7461. for (int index = 0; index < AC_QUANTITY; index++)
  7462. {
  7463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7464. {
  7465. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7466. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7468. {
  7469. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7470. }
  7471. else
  7472. {
  7473. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7474. }
  7475. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7476. goto end;
  7477. }
  7478. }
  7479. }
  7480. //The reservationId does NOT match the reservationId
  7481. sendCancelReservationConfirmation(uuid, comfirmstr);
  7482. end:
  7483. // Fill in ocpp packet uuid
  7484. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7485. return result;
  7486. }
  7487. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7488. {
  7489. mtrace();
  7490. int result = FAIL;
  7491. int gunIndex = -1;
  7492. char typeStr[16]={0};
  7493. char comfirmstr[20];
  7494. int specificId = FALSE;
  7495. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7496. json_object *ChangeAvailability;
  7497. ChangeAvailability = json_tokener_parse(payload);
  7498. if(!is_error(ChangeAvailability))
  7499. {
  7500. // Required data
  7501. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7502. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7503. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7504. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7505. }
  7506. json_object_put(ChangeAvailability);
  7507. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7508. {
  7509. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7510. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7511. }
  7512. else if(gunIndex == 0)
  7513. {
  7514. for(int i=0; i < gunTotalNumber; i++)
  7515. {
  7516. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7517. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7518. }
  7519. }
  7520. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7522. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7523. {
  7524. specificId = TRUE;
  7525. }
  7526. if(specificId == FALSE)
  7527. goto end;
  7528. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7529. {
  7530. //----------------------gunIndex is 0 ------------------------------------------------//
  7531. if(gunIndex == 0)
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7534. {
  7535. for(int i=0; i < gunTotalNumber; i++)
  7536. {
  7537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7538. {
  7539. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7540. {
  7541. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7542. {
  7543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7544. goto end;
  7545. }
  7546. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7549. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7550. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7551. {
  7552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7553. goto end;
  7554. }
  7555. }
  7556. }//END FOR CHAdeMO_QUANTITY
  7557. for (int index = 0; index < CCS_QUANTITY; index++)
  7558. {
  7559. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7560. {
  7561. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7562. {
  7563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7564. goto end;
  7565. }
  7566. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7571. {
  7572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7573. goto end;
  7574. }
  7575. }
  7576. }//END FOR CCS_QUANTITY
  7577. for (int index = 0; index < GB_QUANTITY; index++)
  7578. {
  7579. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7580. {
  7581. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7582. {
  7583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7584. goto end;
  7585. }
  7586. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7591. {
  7592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7593. goto end;
  7594. }
  7595. }
  7596. }// END FOR GB_QUANTITY
  7597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7598. {
  7599. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7600. {
  7601. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7602. {
  7603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7604. goto end;
  7605. }
  7606. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7610. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7611. {
  7612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7613. goto end;
  7614. }
  7615. }
  7616. }// END FOR GENERAL_GUN_QUANTITY
  7617. for (int index = 0; index < AC_QUANTITY; index++)
  7618. {
  7619. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7620. {
  7621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7622. {
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7624. goto end;
  7625. }
  7626. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7631. {
  7632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7633. goto end;
  7634. }
  7635. }
  7636. }//END FOR AC_QUANTITY
  7637. }// END FOR gunTotalNumber
  7638. }
  7639. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7640. {
  7641. for(int i=0; i < gunTotalNumber; i++)
  7642. {
  7643. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7644. {
  7645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7646. goto end;
  7647. }
  7648. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7655. goto end;
  7656. }
  7657. }
  7658. }
  7659. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7660. goto end;
  7661. }
  7662. //----------------------gunIndex is not 0 ------------------------------------------------//
  7663. //check Transaction active
  7664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7665. {
  7666. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7667. {
  7668. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7669. {
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7671. goto end;
  7672. }
  7673. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7680. goto end;
  7681. }
  7682. else
  7683. {
  7684. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7686. goto end;
  7687. }
  7688. }
  7689. }//END FOR CHAdeMO_QUANTITY
  7690. for (int index = 0; index < CCS_QUANTITY; index++)
  7691. {
  7692. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7693. {
  7694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7695. {
  7696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7697. goto end;
  7698. }
  7699. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7703. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7704. {
  7705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7706. goto end;
  7707. }
  7708. else
  7709. {
  7710. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }
  7715. }//END FOR CCS_QUANTITY
  7716. for (int index = 0; index < GB_QUANTITY; index++)
  7717. {
  7718. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7719. {
  7720. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7721. {
  7722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7723. goto end;
  7724. }
  7725. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7729. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7730. {
  7731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7732. goto end;
  7733. }
  7734. else
  7735. {
  7736. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7738. goto end;
  7739. }
  7740. }
  7741. }// END FOR GB_QUANTITY
  7742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7743. {
  7744. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7745. {
  7746. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7747. {
  7748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7749. goto end;
  7750. }
  7751. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7756. {
  7757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7758. goto end;
  7759. }
  7760. else
  7761. {
  7762. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7763. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7764. goto end;
  7765. }
  7766. }
  7767. }// END FOR GENERAL_GUN_QUANTITY
  7768. for (int index = 0; index < AC_QUANTITY; index++)
  7769. {
  7770. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7771. {
  7772. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7773. {
  7774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7775. goto end;
  7776. }
  7777. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7781. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7782. {
  7783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7784. goto end;
  7785. }
  7786. else
  7787. {
  7788. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7790. goto end;
  7791. }
  7792. }
  7793. }//END FOR AC_QUANTITY
  7794. }//END FOR AvailabilityTypeStr[Inoperative]
  7795. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7796. {
  7797. //----------------------gunIndex is 0 ------------------------------------------------//
  7798. if(gunIndex == 0)
  7799. {
  7800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7801. {
  7802. for(int i=0; i < gunTotalNumber; i++)
  7803. {
  7804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7805. {
  7806. 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
  7807. {
  7808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7809. goto end;
  7810. }
  7811. }//END FOR CHAdeMO_QUANTITY
  7812. for (int index = 0; index < CCS_QUANTITY; index++)
  7813. {
  7814. 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
  7815. {
  7816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7817. goto end;
  7818. }
  7819. }//END FOR CCS_QUANTITY
  7820. for (int index = 0; index < GB_QUANTITY; index++)
  7821. {
  7822. 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
  7823. {
  7824. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7826. goto end;
  7827. }
  7828. }// END FOR GB_QUANTITY
  7829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7830. {
  7831. 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
  7832. {
  7833. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7835. goto end;
  7836. }
  7837. }// END FOR GENERAL_GUN_QUANTITY
  7838. for (int index = 0; index < AC_QUANTITY; index++)
  7839. {
  7840. 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
  7841. {
  7842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7843. goto end;
  7844. }
  7845. }//END FOR CHAdeMO_QUANTITY
  7846. }// END FOR gunTotalNumber
  7847. }
  7848. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7849. {
  7850. for(int i=0; i < gunTotalNumber; i++)
  7851. {
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. 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
  7855. {
  7856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7857. goto end;
  7858. }
  7859. }//END FOR CHAdeMO_QUANTITY
  7860. } // END FOR gunTotalNumber
  7861. }
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7863. goto end;
  7864. }
  7865. //----------------------gunIndex is not 0 ------------------------------------------------//
  7866. //check Transaction active
  7867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7868. {
  7869. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7872. goto end;
  7873. }
  7874. }//END FOR CHAdeMO_QUANTITY
  7875. for (int index = 0; index < CCS_QUANTITY; index++)
  7876. {
  7877. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7880. goto end;
  7881. }
  7882. }//END FOR CCS_QUANTITY
  7883. for (int index = 0; index < GB_QUANTITY; index++)
  7884. {
  7885. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7886. {
  7887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7888. goto end;
  7889. }
  7890. }// END FOR GB_QUANTITY
  7891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7892. {
  7893. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7894. {
  7895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7896. goto end;
  7897. }
  7898. }// END FOR GENERAL_GUN_QUANTITY
  7899. for (int index = 0; index < AC_QUANTITY; index++)
  7900. {
  7901. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7902. {
  7903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7904. goto end;
  7905. }
  7906. }//END FOR AC_QUANTITY
  7907. }//END FOR AvailabilityTypeStr[Operative]
  7908. end:
  7909. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7910. {
  7911. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7912. }
  7913. else
  7914. {
  7915. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7916. }
  7917. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7918. {
  7919. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7920. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7921. }
  7922. else if(gunIndex == 0)
  7923. {
  7924. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7925. {
  7926. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7927. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7928. }
  7929. }
  7930. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7932. return result;
  7933. }
  7934. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7935. {
  7936. mtrace();
  7937. int valueInvalid = NO;
  7938. int result = FAIL;
  7939. char keystr[40]={0};
  7940. char valuestr[501]={0}; //value should be limited in 500 bytes
  7941. char comfirmstr[20]={0};
  7942. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7943. json_object *ChangeConfiguration;
  7944. ChangeConfiguration = json_tokener_parse(payload);
  7945. if(!is_error(ChangeConfiguration))
  7946. {
  7947. // Required data
  7948. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7949. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7950. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  7951. {
  7952. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7953. }
  7954. else
  7955. {
  7956. valueInvalid = YES;
  7957. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  7958. }
  7959. }
  7960. json_object_put(ChangeConfiguration);
  7961. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  7962. {
  7963. DEBUG_ERROR("Payload is null or not accepted.\n");
  7964. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7965. }
  7966. else
  7967. {
  7968. int status = setKeyValue(keystr, valuestr);
  7969. switch(status)
  7970. {
  7971. case ConfigurationStatus_Accepted:
  7972. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7973. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7974. StoreConfigurationTable();
  7975. break;
  7976. case RebootRequired:
  7977. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7978. StoreConfigurationTable();
  7979. break;
  7980. case NotSupported:
  7981. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7982. break;
  7983. case ConfigurationStatus_Rejected:
  7984. default:
  7985. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7986. break;
  7987. }
  7988. }
  7989. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7990. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7991. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7992. {
  7993. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7994. SetOcppConnStatus(FALSE);
  7995. }
  7996. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7997. {
  7998. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7999. }
  8000. return result;
  8001. }
  8002. int handleClearCacheRequest(char *uuid, char *payload)
  8003. {
  8004. mtrace();
  8005. int result = FAIL;
  8006. char comfirmstr[20];
  8007. char rmFileCmd[100]={0};
  8008. struct stat stats;
  8009. DEBUG_INFO("handleClearCacheRequest...\n");
  8010. stat("/Storage/OCPP_PH", &stats);
  8011. // Check for directory existence
  8012. if (S_ISDIR(stats.st_mode) == 1)
  8013. {}
  8014. else
  8015. {
  8016. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8017. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8018. system(rmFileCmd);
  8019. }
  8020. if(OCPP_cleanLocalCache())
  8021. {
  8022. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8023. }
  8024. else
  8025. {
  8026. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8027. }
  8028. sendClearCacheConfirmation(uuid, comfirmstr);
  8029. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8030. return result;
  8031. }
  8032. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8033. {
  8034. mtrace();
  8035. int result = FAIL;
  8036. int resultRename;
  8037. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8038. char chargingProfilePurposeStr[26]={0};
  8039. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8040. char tempchargingProfilePurposeStr[26]={0};
  8041. char str[100]={0};
  8042. char fname[200]={0};
  8043. char comfirmstr[20]={0};
  8044. char word[1600]={0};
  8045. int clearflag = FALSE;
  8046. int chargingProfileIdIsNULL = FALSE;
  8047. int connectorIsNULL = FALSE;
  8048. int chargingProfilePurposeIsNULL = FALSE;
  8049. int stackLevelIsNULL = FALSE;
  8050. //int GotoEnd = FALSE;
  8051. FILE *fptr1, *fptr2;
  8052. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8053. int n_chargingProfile=0;
  8054. int isEmptyFile = FALSE;
  8055. char sLineWord[1600]={0};
  8056. char chargingProfiles[10][100]={0};
  8057. int ChargeProfileCount = 0;
  8058. int ch;
  8059. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8060. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8061. json_object *ClearChargingProfile;
  8062. ClearChargingProfile = json_tokener_parse(payload);
  8063. if(!is_error(ClearChargingProfile))
  8064. {
  8065. // Optional data
  8066. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8067. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8068. else
  8069. chargingProfileIdIsNULL = TRUE;
  8070. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8071. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8072. else
  8073. connectorIsNULL = TRUE;
  8074. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8075. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8076. else
  8077. chargingProfilePurposeIsNULL = TRUE;
  8078. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8079. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8080. else
  8081. stackLevelIsNULL = TRUE;
  8082. }
  8083. json_object_put(ClearChargingProfile);
  8084. if(connectorIsNULL == FALSE)
  8085. {
  8086. switch(connectorIdInt)
  8087. {
  8088. case 0:
  8089. if(chargingProfilePurposeIsNULL == TRUE)
  8090. {
  8091. int l = 0;
  8092. strcpy(fname, ChargePointMaxProfile_JSON);
  8093. if((access(fname,F_OK))!=-1)
  8094. {
  8095. strcpy(chargingProfiles[l], fname);
  8096. l = l + 1;
  8097. }
  8098. strcpy(fname, TxDefaultProfile_0_JSON);
  8099. if((access(fname,F_OK))!=-1)
  8100. {
  8101. strcpy(chargingProfiles[l], fname);
  8102. l = l + 1;
  8103. }
  8104. ChargeProfileCount = l;
  8105. }
  8106. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8107. {
  8108. strcpy(fname, ChargePointMaxProfile_JSON);
  8109. if((access(fname,F_OK))!=-1)
  8110. {
  8111. strcpy(chargingProfiles[0], fname);
  8112. ChargeProfileCount = 1;
  8113. }
  8114. }
  8115. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8116. {
  8117. strcpy(fname, TxDefaultProfile_0_JSON);
  8118. if((access(fname,F_OK))!=-1)
  8119. {
  8120. strcpy(chargingProfiles[0], fname);
  8121. ChargeProfileCount = 1;
  8122. }
  8123. }
  8124. break;
  8125. default:
  8126. if(chargingProfilePurposeIsNULL == TRUE)
  8127. {
  8128. int m = 0;
  8129. memset(fname, 0, ARRAY_SIZE(fname));
  8130. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8131. if((access(fname,F_OK))!=-1)
  8132. {
  8133. strcpy(chargingProfiles[m], fname);
  8134. m = m + 1;
  8135. }
  8136. memset(fname, 0, ARRAY_SIZE(fname));
  8137. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8138. if((access(fname,F_OK))!=-1)
  8139. {
  8140. strcpy(chargingProfiles[m], fname);
  8141. m = m + 1;
  8142. }
  8143. ChargeProfileCount = m;
  8144. }
  8145. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8146. {
  8147. //strcpy(fname, TxDefaultProfile_1_JSON);
  8148. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8149. if((access(fname,F_OK))!=-1)
  8150. {
  8151. strcpy(chargingProfiles[0], fname);
  8152. ChargeProfileCount = 1;
  8153. }
  8154. }
  8155. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8156. {
  8157. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8158. if((access(fname,F_OK))!=-1)
  8159. {
  8160. strcpy(chargingProfiles[0], fname);
  8161. ChargeProfileCount = 1;
  8162. }
  8163. //strcpy(fname, TxProfile_1_JSON);
  8164. }
  8165. //strcpy(fname, ChargePointMaxProfile_JSON );
  8166. break;
  8167. }
  8168. }
  8169. else // Check all Charging Profiles
  8170. {
  8171. int i = 0;
  8172. char fnametemp[200]={0};
  8173. ChargeProfileCount = 0;
  8174. //Check ChargePointMaxProfile.json exit
  8175. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8176. {
  8177. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8178. i = i + 1;
  8179. }
  8180. //Check TxDefaultProfile_0.json exit
  8181. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8184. i = i + 1;
  8185. }
  8186. //Check TxDefaultProfile_%d.json
  8187. for(int j=1; j <= gunTotalNumber; j++)
  8188. {
  8189. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8190. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8191. if((access(fnametemp,F_OK))!=-1)
  8192. {
  8193. strcpy(chargingProfiles[i], fnametemp);
  8194. i = i + 1;
  8195. }
  8196. }
  8197. //Check TxProfile_%d.json
  8198. for(int j=1; j <= gunTotalNumber; j++)
  8199. {
  8200. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8201. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8202. if((access(fnametemp,F_OK))!=-1)
  8203. {
  8204. strcpy(chargingProfiles[i], fnametemp);
  8205. i = i + 1;
  8206. }
  8207. }
  8208. ChargeProfileCount = i;
  8209. }// End connectorIsNULL is TRUE
  8210. if(ChargeProfileCount == 0)
  8211. {
  8212. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8213. goto end;
  8214. }
  8215. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8216. {
  8217. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8218. goto end;
  8219. }
  8220. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8221. {
  8222. memset(str, 0, ARRAY_SIZE(str));
  8223. // clear temp file
  8224. sprintf(str,"rm -f %s",temp);
  8225. system(str);
  8226. for(int k=0; k < ChargeProfileCount; k++)
  8227. {
  8228. memset(str, 0, ARRAY_SIZE(str));
  8229. //clear file in C
  8230. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8231. system(str);
  8232. }
  8233. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8234. goto end;
  8235. }
  8236. else if(connectorIsNULL == TRUE)
  8237. {
  8238. for(int k=0; k < ChargeProfileCount; k++)
  8239. {
  8240. fptr1 = fopen(chargingProfiles[k], "r");
  8241. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8242. //Check Charging Profile Count
  8243. while(fscanf(fptr1, "%s", word) != EOF)
  8244. {
  8245. //DEBUG_INFO("word=%s\n",word);
  8246. if(strstr(word, "chargingProfileId")!= NULL)
  8247. {
  8248. //DEBUG_INFO("test chargingProfileId \n");
  8249. n_chargingProfile = n_chargingProfile + 1;
  8250. //DEBUG_INFO("chargingProfileId Found\n");
  8251. }
  8252. }
  8253. rewind(fptr1);
  8254. //search Charging Profile Element
  8255. //int i= 0;
  8256. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8257. {
  8258. json_object *tmpProfilee;
  8259. tmpProfilee = json_tokener_parse(sLineWord);
  8260. if(!is_error(tmpProfilee))
  8261. {
  8262. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8263. {
  8264. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8265. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8266. }
  8267. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8268. {
  8269. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8270. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8271. }
  8272. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8273. {
  8274. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8275. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8276. }
  8277. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8278. {
  8279. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8280. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8281. }
  8282. }
  8283. json_object_put(tmpProfilee);
  8284. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8285. {
  8286. //------- not write to fptr2-------//
  8287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8288. //clearflag = TRUE;
  8289. }
  8290. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8291. {
  8292. //------- not write to fptr2-------//
  8293. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8294. }
  8295. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8296. {
  8297. //------- not write to fptr2-------//
  8298. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8299. }
  8300. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8301. {
  8302. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8303. }
  8304. else
  8305. {
  8306. fprintf(fptr2, sLineWord);//writing data into file
  8307. }
  8308. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8309. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8310. if(clearflag == TRUE)
  8311. {
  8312. fclose(fptr1);
  8313. fclose(fptr2);
  8314. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8315. system(str);
  8316. // clear temp file
  8317. sprintf(str,"rm -f %s",temp);
  8318. system(str);
  8319. }
  8320. else
  8321. {
  8322. fclose(fptr1);
  8323. fclose(fptr2);
  8324. memset(str, 0, ARRAY_SIZE(str));
  8325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8326. system(str);
  8327. resultRename = rename(temp, chargingProfiles[k]);
  8328. if(resultRename == 0)
  8329. {
  8330. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8331. }
  8332. else
  8333. {
  8334. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8335. }
  8336. if(comfirmstr[0]== 0)
  8337. {
  8338. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8339. }
  8340. //Check chargingProfile is empty file
  8341. /*------ Read the file ----------------*/
  8342. fptr1=fopen(chargingProfiles[k],"r");
  8343. ch=fgetc(fptr1);
  8344. rewind(fptr1);
  8345. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8346. if(ch!=EOF)
  8347. {
  8348. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8349. {
  8350. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8351. if(sLineWord[0]=='\0')
  8352. {
  8353. isEmptyFile = TRUE;
  8354. break;
  8355. }
  8356. else
  8357. {
  8358. isEmptyFile = FALSE;
  8359. break;
  8360. }
  8361. }
  8362. }
  8363. else
  8364. isEmptyFile = TRUE;
  8365. fclose(fptr1);
  8366. if(isEmptyFile == TRUE)
  8367. {
  8368. memset(str, 0, ARRAY_SIZE(str));
  8369. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8370. system(str);
  8371. }
  8372. }
  8373. }// End of while(int k=0; k < ChargePointCount; k++)
  8374. }
  8375. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8376. {
  8377. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8378. for(int k=0; k < ChargeProfileCount; k++)
  8379. {
  8380. fptr1 = fopen(chargingProfiles[k], "r");
  8381. fptr2 = fopen(temp, "w+");
  8382. //Check Charging Profile Count
  8383. while(fscanf(fptr1, "%s", word) != EOF)
  8384. {
  8385. //DEBUG_INFO("word=%s\n",word);
  8386. if(strstr(word, "chargingProfileId")!= NULL)
  8387. {
  8388. n_chargingProfile = n_chargingProfile + 1;
  8389. }
  8390. }
  8391. rewind(fptr1);
  8392. //search Charging Profile Element
  8393. //int i= 0;
  8394. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8395. {
  8396. json_object *tmpProfilee;
  8397. tmpProfilee = json_tokener_parse(sLineWord);
  8398. if(!is_error(tmpProfilee))
  8399. {
  8400. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8401. {
  8402. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8403. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8404. }
  8405. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8406. {
  8407. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8408. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8409. }
  8410. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8411. {
  8412. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8413. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8414. }
  8415. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8416. {
  8417. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8418. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8419. }
  8420. }
  8421. json_object_put(tmpProfilee);
  8422. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8423. {
  8424. //------- not write to fptr2-------//
  8425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8426. //clearflag = TRUE;
  8427. }
  8428. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8429. {
  8430. //------- not write to fptr2-------//
  8431. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8432. }
  8433. else if(stackLevelIsNULL == TRUE)
  8434. {
  8435. //Clear Whole File
  8436. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8437. clearflag = TRUE;
  8438. break;
  8439. }
  8440. else
  8441. {
  8442. fprintf(fptr2, sLineWord);//writing data into file
  8443. }
  8444. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8445. }
  8446. if(clearflag == TRUE)
  8447. {
  8448. fclose(fptr1);
  8449. fclose(fptr2);
  8450. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8451. system(str);
  8452. // clear temp file
  8453. sprintf(str,"rm -f %s",temp);
  8454. system(str);
  8455. }
  8456. else
  8457. {
  8458. fclose(fptr1);
  8459. fclose(fptr2);
  8460. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8461. system(str);
  8462. resultRename = rename(temp, chargingProfiles[k]);
  8463. if(resultRename == 0)
  8464. {
  8465. DEBUG_INFO("File ChargingProfile renamed successfully");
  8466. }
  8467. else
  8468. {
  8469. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8470. }
  8471. if(comfirmstr[0]== 0)
  8472. {
  8473. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8474. }
  8475. //Check chargingProfile is empty file
  8476. /*------ Read the file ----------------*/
  8477. fptr1=fopen(chargingProfiles[k],"r");
  8478. ch=fgetc(fptr1);
  8479. rewind(fptr1);
  8480. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8481. if(ch!=EOF)
  8482. {
  8483. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8484. {
  8485. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8486. if(sLineWord[0]=='\0')
  8487. {
  8488. isEmptyFile = TRUE;
  8489. break;
  8490. }
  8491. else
  8492. {
  8493. isEmptyFile = FALSE;
  8494. break;
  8495. }
  8496. }
  8497. }
  8498. else
  8499. isEmptyFile = TRUE;
  8500. fclose(fptr1);
  8501. if(isEmptyFile == TRUE)
  8502. {
  8503. memset(str, 0, ARRAY_SIZE(str));
  8504. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8505. system(str);
  8506. }
  8507. /*------- End of reading ---------------*/
  8508. }
  8509. } // while(int k=0; k < ChargeProfileCount; k++)
  8510. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8511. end:
  8512. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8513. {
  8514. if(connectorIdInt == 0)
  8515. {
  8516. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8517. {
  8518. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8519. }
  8520. }
  8521. else
  8522. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8523. }
  8524. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8525. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8526. return result;
  8527. }
  8528. void createFirmwareVersionByDataTransfer(void)
  8529. {
  8530. json_object *FirmwareDataTransfer = json_object_new_object();
  8531. // AC & DC model
  8532. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8533. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8534. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8535. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8536. // DC model
  8537. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8538. {
  8539. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8540. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8541. (gunType[3] != GUN_TYPE_UNKNOWN))
  8542. {
  8543. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8544. }
  8545. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8546. {
  8547. // DS DM DW
  8548. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8549. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8550. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8551. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8552. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8553. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8554. }
  8555. else
  8556. {
  8557. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8559. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8560. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8561. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8562. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8563. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8564. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8565. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8566. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8567. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8568. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8569. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8573. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8575. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8577. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8579. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8581. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8583. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8584. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8585. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8586. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8587. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8588. }
  8589. }
  8590. // 4G model
  8591. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8592. {
  8593. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8594. }
  8595. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8596. json_object_put(FirmwareDataTransfer);
  8597. }
  8598. int handleDataTransferRequest(char *uuid, char *payload)
  8599. {
  8600. mtrace();
  8601. json_object *response = json_object_new_object();
  8602. int result = FAIL;
  8603. char tempvendorId[255]={0};
  8604. char tempmessageId[50]={0};
  8605. char tempdata[512]={0};
  8606. char message[2048]={0};
  8607. DEBUG_INFO("handleDataTransferRequest...\n");
  8608. if((uuid != NULL) && (payload != NULL))
  8609. {
  8610. json_object *DataTransfer;
  8611. DataTransfer = json_tokener_parse(payload);
  8612. if(!is_error(DataTransfer))
  8613. {
  8614. // Required data
  8615. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8616. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8617. // Optional data
  8618. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8619. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8620. if(json_object_object_get(DataTransfer, "data") != NULL)
  8621. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8622. result = PASS;
  8623. }
  8624. json_object_put(DataTransfer);
  8625. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8626. {
  8627. // Send all moudle firmware version on EVSE
  8628. createFirmwareVersionByDataTransfer();
  8629. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8630. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8631. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8632. json_object_put(response);
  8633. }
  8634. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8635. {
  8636. system("/usr/bin/run_tmate_restart.sh &");
  8637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8638. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8639. json_object_put(response);
  8640. }
  8641. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8642. {
  8643. json_object *data;
  8644. data = json_tokener_parse(tempdata);
  8645. if(!is_error(data))
  8646. {
  8647. 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))
  8648. {
  8649. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8650. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8651. if(json_object_object_get(data, "SOC") != NULL)
  8652. {
  8653. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8654. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8655. }
  8656. if(json_object_object_get(data, "Energy") != NULL)
  8657. {
  8658. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8659. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8660. }
  8661. if(json_object_object_get(data, "Duration") != NULL)
  8662. {
  8663. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8664. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8665. }
  8666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8667. }
  8668. else
  8669. {
  8670. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8671. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8672. }
  8673. }
  8674. else
  8675. {
  8676. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8677. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8678. }
  8679. json_object_put(data);
  8680. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8681. json_object_put(response);
  8682. }
  8683. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8684. {
  8685. json_object *data;
  8686. data = json_tokener_parse(tempdata);
  8687. if(!is_error(data))
  8688. {
  8689. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8690. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8691. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8692. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8693. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8694. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8695. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8696. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8697. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8698. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8699. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8700. }
  8701. else
  8702. {
  8703. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8704. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8705. }
  8706. json_object_put(data);
  8707. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8708. json_object_put(response);
  8709. }
  8710. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8711. {
  8712. json_object *data;
  8713. data = json_tokener_parse(tempdata);
  8714. if(!is_error(data))
  8715. {
  8716. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8717. if(json_object_object_get(data, "idToken") != NULL)
  8718. {
  8719. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8720. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8721. }
  8722. if(json_object_object_get(data, "price") != NULL)
  8723. {
  8724. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8725. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8726. }
  8727. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8728. }
  8729. else
  8730. {
  8731. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8732. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8733. }
  8734. json_object_put(data);
  8735. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8736. json_object_put(response);
  8737. }
  8738. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8739. {
  8740. json_object *data;
  8741. data = json_tokener_parse(tempdata);
  8742. if(!is_error(data))
  8743. {
  8744. if(json_object_object_get(data, "txId") != NULL)
  8745. {
  8746. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8747. for(int idx = 0;idx<gunTotalNumber;idx++)
  8748. {
  8749. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8750. {
  8751. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8752. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8753. if(json_object_object_get(data, "description") != NULL)
  8754. {
  8755. // California pricing V1.0
  8756. DEBUG_INFO("California pricing V1.0\n");
  8757. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8758. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8759. }
  8760. else
  8761. {
  8762. // California pricing V1.1
  8763. DEBUG_INFO("California pricing V1.1\n");
  8764. if(json_object_object_get(data, "timestamp") != NULL)
  8765. {
  8766. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8767. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8768. }
  8769. if(json_object_object_get(data, "meterValue") != NULL)
  8770. {
  8771. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8772. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8773. }
  8774. if(json_object_object_get(data, "cost") != NULL)
  8775. {
  8776. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8777. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8778. }
  8779. if(json_object_object_get(data, "state") != NULL)
  8780. {
  8781. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8782. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8783. }
  8784. if(json_object_object_get(data, "chargingPrice") != NULL)
  8785. {
  8786. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8787. {
  8788. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8789. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8790. }
  8791. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8792. {
  8793. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8794. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8795. }
  8796. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8797. {
  8798. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8799. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8800. }
  8801. }
  8802. if(json_object_object_get(data, "idlePrice") != NULL)
  8803. {
  8804. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8805. {
  8806. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8807. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8808. }
  8809. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8810. {
  8811. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8812. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8813. }
  8814. }
  8815. if(json_object_object_get(data, "nextPeriod") != NULL)
  8816. {
  8817. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8818. {
  8819. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8820. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8821. }
  8822. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8823. {
  8824. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8825. {
  8826. 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")));
  8827. 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"));
  8828. }
  8829. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8830. {
  8831. 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")));
  8832. 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"));
  8833. }
  8834. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8835. {
  8836. 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")));
  8837. 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"));
  8838. }
  8839. }
  8840. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8841. {
  8842. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8843. {
  8844. 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")));
  8845. 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"));
  8846. }
  8847. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8848. {
  8849. 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")));
  8850. 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"));
  8851. }
  8852. }
  8853. }
  8854. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8855. {
  8856. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8857. {
  8858. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8859. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8860. }
  8861. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8862. {
  8863. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8864. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8865. }
  8866. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8867. {
  8868. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8869. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8870. }
  8871. }
  8872. }
  8873. }
  8874. }
  8875. }
  8876. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8877. }
  8878. else
  8879. {
  8880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8881. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8882. }
  8883. json_object_put(data);
  8884. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8885. json_object_put(response);
  8886. }
  8887. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8888. {
  8889. json_object *data;
  8890. data = json_tokener_parse(tempdata);
  8891. if(!is_error(data))
  8892. {
  8893. if(json_object_object_get(data, "txId") != NULL)
  8894. {
  8895. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8896. for(int idx = 0;idx<gunTotalNumber;idx++)
  8897. {
  8898. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8899. {
  8900. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8901. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8902. if(json_object_object_get(data, "description") != NULL)
  8903. {
  8904. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8905. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8906. }
  8907. }
  8908. }
  8909. }
  8910. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8911. }
  8912. else
  8913. {
  8914. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8915. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8916. }
  8917. json_object_put(data);
  8918. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8919. json_object_put(response);
  8920. }
  8921. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8922. {
  8923. json_object *data;
  8924. data = json_tokener_parse(tempdata);
  8925. if(!is_error(data))
  8926. {
  8927. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8928. if(json_object_object_get(data, "Content_Type") != NULL)
  8929. {
  8930. 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))
  8931. {
  8932. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8933. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8934. {
  8935. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8936. }
  8937. }
  8938. else
  8939. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8940. }
  8941. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8942. }
  8943. else
  8944. {
  8945. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8946. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8947. }
  8948. json_object_put(data);
  8949. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8950. json_object_put(response);
  8951. }
  8952. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8953. {
  8954. json_object *data;
  8955. data = json_tokener_parse(tempdata);
  8956. if(!is_error(data))
  8957. {
  8958. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8959. if(json_object_object_get(data, "Page_Index") != NULL)
  8960. {
  8961. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8962. }
  8963. if(json_object_object_get(data, "Duration") != NULL)
  8964. {
  8965. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8966. }
  8967. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8968. }
  8969. else
  8970. {
  8971. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8972. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8973. }
  8974. json_object_put(data);
  8975. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8976. json_object_put(response);
  8977. }
  8978. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8979. {
  8980. json_object *data;
  8981. data = json_tokener_parse(tempdata);
  8982. if(!is_error(data))
  8983. {
  8984. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8985. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8986. {
  8987. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8988. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8989. else
  8990. {
  8991. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8992. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8993. }
  8994. }
  8995. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8996. {
  8997. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8998. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8999. else
  9000. {
  9001. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9002. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9003. }
  9004. }
  9005. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9006. {
  9007. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9008. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9009. else
  9010. {
  9011. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9012. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9013. }
  9014. }
  9015. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9016. {
  9017. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9018. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9019. else
  9020. {
  9021. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9022. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9023. }
  9024. }
  9025. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9026. {
  9027. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9028. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9029. else
  9030. {
  9031. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9032. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9033. }
  9034. }
  9035. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9036. {
  9037. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9038. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9039. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9040. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9041. else
  9042. {
  9043. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9044. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9045. }
  9046. }
  9047. if(json_object_object_get(data, "isAuthentication") != NULL)
  9048. {
  9049. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9050. {
  9051. case 0:
  9052. case 1:
  9053. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9054. break;
  9055. default:
  9056. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9057. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9058. break;
  9059. }
  9060. }
  9061. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9062. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9063. }
  9064. else
  9065. {
  9066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9068. }
  9069. json_object_put(data);
  9070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9071. json_object_put(response);
  9072. }
  9073. else
  9074. {
  9075. // Can not find valid message id
  9076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9077. }
  9078. }
  9079. else
  9080. {
  9081. // Payload is null
  9082. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9083. }
  9084. LWS_Send(message);
  9085. return result;
  9086. }
  9087. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9088. {
  9089. mtrace();
  9090. int result = FAIL;
  9091. int connectorIdInt, durationInt;
  9092. char chargingRateUnitStr[4]={0};
  9093. char comfirmstr[20];
  9094. int confirmPeriods = 0;
  9095. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9096. json_object *GetCompositeSchedule;
  9097. GetCompositeSchedule = json_tokener_parse(payload);
  9098. if(!is_error(GetCompositeSchedule))
  9099. {
  9100. // Required data
  9101. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9102. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9103. else
  9104. connectorIdInt = -1;
  9105. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9106. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9107. else
  9108. durationInt = 86400;
  9109. // Optional data
  9110. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9111. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9112. }
  9113. json_object_put(GetCompositeSchedule);
  9114. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9115. if((connectorIdInt == 0) ||
  9116. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9117. {
  9118. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9119. struct StructChargingProfile tmpProfile[1];
  9120. if(strstr(chargingRateUnitStr, "W") != NULL)
  9121. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9122. else
  9123. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9124. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9125. {
  9126. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9127. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9128. }
  9129. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9130. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9131. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9132. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9133. {
  9134. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9135. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9136. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9137. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9138. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9139. {
  9140. confirmPeriods = idx;
  9141. break;
  9142. }
  9143. }
  9144. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9145. {
  9146. confirmPeriods += 1;
  9147. }
  9148. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9149. }
  9150. else
  9151. {
  9152. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9153. }
  9154. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9155. return result;
  9156. }
  9157. int handleGetConfigurationRequest(char *uuid, char *payload)
  9158. {
  9159. mtrace();
  9160. int result = FAIL;
  9161. int MaxKeySupported = 0;
  9162. int n_keys = 0;
  9163. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9164. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9165. json_object *GetConfiguration;
  9166. GetConfiguration = json_tokener_parse(payload);
  9167. if(!is_error(GetConfiguration))
  9168. {
  9169. // Optional data
  9170. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9171. {
  9172. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9173. {
  9174. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9175. n_keys = idx + 1;
  9176. }
  9177. }
  9178. }
  9179. json_object_put(GetConfiguration);
  9180. UnknownKeynum = 0;
  9181. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9182. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9183. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9184. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9185. if(n_keys != 0)
  9186. {
  9187. for(int i=0;i<n_keys;i++)
  9188. {
  9189. getKeyValue(requestKey[i]);
  9190. }
  9191. }
  9192. else
  9193. {
  9194. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9195. getKeyValue("");
  9196. }
  9197. processUnkownKey();
  9198. sendGetConfigurationConfirmation(uuid);
  9199. return result;
  9200. }
  9201. static char fnamePlusPath[100]={0};
  9202. static char fnamePWithNoPath[60]={0};
  9203. void checkUploadLog(void)
  9204. {
  9205. FILE *fp;
  9206. /* Open the command for reading. */
  9207. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9208. if (fp == NULL) {
  9209. DEBUG_WARN("Failed to run command\n" );
  9210. exit(1);
  9211. }
  9212. int ftppathlen = 0;
  9213. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9214. int i = 0;
  9215. /* Read the output a line at a time - output it. */
  9216. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9217. if(i==0)
  9218. {
  9219. ftppathlen = strlen(fnamePlusPath);
  9220. DEBUG_INFO("%s\n", fnamePlusPath);
  9221. fnamePlusPath[ftppathlen]='\0';
  9222. break;
  9223. }
  9224. i= i+1;
  9225. }
  9226. /* close */
  9227. pclose(fp);
  9228. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9229. {
  9230. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9231. {
  9232. fnamePlusPath[k]='\0';
  9233. }
  9234. }
  9235. i=1;
  9236. //char fname[60]={0};
  9237. while(i < ftppathlen)
  9238. {
  9239. int len=ftppathlen-i;
  9240. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9241. {
  9242. DEBUG_INFO("compare '/' all right\n");
  9243. break;
  9244. }
  9245. i=i+1;
  9246. }
  9247. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9248. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9249. fnamePWithNoPath[i+1] = '\0';
  9250. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9251. {
  9252. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9253. {
  9254. fnamePWithNoPath[j]='\0';
  9255. }
  9256. }
  9257. FILE* fp1 = fopen(fnamePlusPath, "r");
  9258. if (fp1)
  9259. {
  9260. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9261. // file exists
  9262. fclose(fp1);
  9263. }
  9264. else
  9265. {
  9266. // file doesn't exist
  9267. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9268. }
  9269. }
  9270. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9271. {
  9272. mtrace();
  9273. int result = FAIL;
  9274. time_t CurrentTime;
  9275. struct tm *tm;
  9276. pthread_t th_Status;
  9277. CurrentTime = time(NULL);
  9278. tm = localtime(&CurrentTime);
  9279. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9280. 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);
  9281. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9282. if(!interLock.isGetDiagnosticGoing)
  9283. {
  9284. interLock.isGetDiagnosticGoing = 1;
  9285. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9286. sleep(1);
  9287. }
  9288. else
  9289. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9290. return result;
  9291. }
  9292. void* GetDiagnosticsProcess(void* data)
  9293. {
  9294. pthread_detach(pthread_self());
  9295. mtrace();
  9296. int retriesInt=0, retryIntervalInt=0;
  9297. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9298. 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};
  9299. int port=0;
  9300. int isSuccess = FALSE;
  9301. char ftpbuf[200]={0};
  9302. char cmdBuf[2048];
  9303. struct tm *tmNow;
  9304. time_t CurrentTime;
  9305. struct tm tmStart;
  9306. struct tm tmStop;
  9307. CurrentTime = time(NULL);
  9308. tmNow=localtime(&CurrentTime);
  9309. uint16_t targetYear, targetMonth;
  9310. json_object *GetDiagnostics;
  9311. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9312. GetDiagnostics = json_tokener_parse(data);
  9313. if(!is_error(GetDiagnostics))
  9314. {
  9315. // Required data
  9316. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9317. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9318. // Optional data
  9319. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9320. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9321. else
  9322. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9323. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9324. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9325. else
  9326. retryIntervalInt = 30;
  9327. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9328. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9329. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9330. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9331. }
  9332. json_object_put(GetDiagnostics);
  9333. // Pack log to compress file
  9334. 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) &&
  9335. (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))
  9336. {
  9337. // Pack system log
  9338. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9339. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9340. targetYear = tmStart.tm_year;
  9341. targetMonth = tmStart.tm_mon;
  9342. do
  9343. {
  9344. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9345. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9346. if(targetMonth+1>=13)
  9347. {
  9348. targetYear += 1;
  9349. targetMonth = 1;
  9350. }
  9351. else
  9352. {
  9353. targetMonth += 1;
  9354. }
  9355. }while((targetYear < (tmNow->tm_year+1900)) ||
  9356. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9357. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9358. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9359. system(cmdBuf);
  9360. // Pack charging & event log
  9361. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9362. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9363. targetYear = tmStart.tm_year;
  9364. targetMonth = tmStart.tm_mon;
  9365. do
  9366. {
  9367. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9368. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9369. if(targetMonth+1>=13)
  9370. {
  9371. targetYear += 1;
  9372. targetMonth = 1;
  9373. }
  9374. else
  9375. {
  9376. targetMonth += 1;
  9377. }
  9378. }while((targetYear < (tmNow->tm_year+1900)) ||
  9379. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9380. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9381. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9382. system(cmdBuf);
  9383. // Combine log file
  9384. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9385. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9386. }
  9387. else
  9388. {
  9389. system("exec /root/logPackTools 'log' 6");
  9390. }
  9391. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9392. system(cmdBuf);
  9393. checkUploadLog();
  9394. //****************location*******************/
  9395. if(strcmp(locationstr,"")==0)
  9396. {
  9397. DEBUG_INFO("location is <Empty>!\n");
  9398. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9399. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9400. goto end;
  9401. }
  9402. memset(protocol, 0, ARRAY_SIZE(protocol));
  9403. memset(user, 0, ARRAY_SIZE(user) );
  9404. memset(password, 0, ARRAY_SIZE(password));
  9405. memset(host, 0, ARRAY_SIZE(host));
  9406. memset(path, 0, ARRAY_SIZE(path));
  9407. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9408. memset(host1, 0, ARRAY_SIZE(host1));
  9409. memset(path1, 0, ARRAY_SIZE(path1));
  9410. /*location: ftp://user:password@host:port/path*/
  9411. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9412. if((access(fnamePlusPath,F_OK))!=-1)
  9413. {
  9414. DEBUG_INFO("fnamePlusPath exist.\n");
  9415. }
  9416. else
  9417. {
  9418. DEBUG_INFO("fnamePlusPath not exist!\n");
  9419. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9420. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9421. goto end;
  9422. }
  9423. if(strchr(locationstr,'@')==NULL)
  9424. {
  9425. sscanf(locationstr,
  9426. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9427. protocol, host, &port, path);
  9428. strcpy(user,"anonymous");
  9429. strcpy(password,"");
  9430. }
  9431. else
  9432. {
  9433. //DEBUG_INFO("pch=%s\n", pch);
  9434. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9435. protocol, user, password, host, &port, path);
  9436. }
  9437. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9438. {
  9439. DEBUG_INFO("protocol is not ftp/http ! \n");
  9440. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9441. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9442. goto end;
  9443. }
  9444. if(strncmp(locationstr,"http", 4) == 0)
  9445. {
  9446. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9447. sprintf(ftppath,"/%s", path);
  9448. do
  9449. {
  9450. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9451. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9452. sleep(3);
  9453. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9454. if(!isSuccess)
  9455. {
  9456. DEBUG_INFO("Diagnostics fail.\n");
  9457. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9458. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9459. sleep(retryIntervalInt);
  9460. }
  9461. else
  9462. {
  9463. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9464. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9465. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9466. }
  9467. retriesInt--;
  9468. }while((isSuccess == 0)&&(retriesInt >= 0));
  9469. }
  9470. else
  9471. {
  9472. sscanf(host,"%[^/]%s",host1, path1);
  9473. if(strlen(path) > 0)
  9474. sprintf(ftppath,"/%s", path);
  9475. else
  9476. sprintf(ftppath,"/%s", path1);
  9477. int ftppathlen=strlen(ftppath);
  9478. int i=1;
  9479. char filenametemp[50];
  9480. while(i < ftppathlen)
  9481. {
  9482. int len=ftppathlen-i;
  9483. if(ftppath[len]== 47) // '/' ascll code: 47
  9484. {
  9485. DEBUG_INFO("find '/' all right\n");
  9486. break;
  9487. }
  9488. i=i+1;
  9489. }
  9490. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9491. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9492. filenametemp[i+1] = 0;
  9493. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9494. if(port == 0)
  9495. port = 21;
  9496. do
  9497. {
  9498. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9499. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9500. sleep(3);
  9501. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9502. if(!isSuccess)
  9503. {
  9504. DEBUG_INFO("Diagnostics fail.\n");
  9505. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9506. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9507. sleep(retryIntervalInt);
  9508. }
  9509. else
  9510. {
  9511. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9512. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9513. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9514. }
  9515. retriesInt--;
  9516. }while((!isSuccess)&&(retriesInt >= 0));
  9517. }
  9518. end:
  9519. system("rm -f /mnt/*");
  9520. sleep(5);
  9521. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9522. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9523. interLock.isGetDiagnosticGoing = 0;
  9524. pthread_exit(NULL);
  9525. }
  9526. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9527. {
  9528. mtrace();
  9529. int result = FAIL;
  9530. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9531. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9532. {
  9533. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9534. locallistVersion = -1;
  9535. }
  9536. else
  9537. {
  9538. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9539. OCPP_getListVerion();
  9540. }
  9541. //from db.OCPP_getListVerion
  9542. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9543. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9544. sendGetLocalListVersionConfirmation(uuid,"");
  9545. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9546. return result;
  9547. }
  9548. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9549. {
  9550. mtrace();
  9551. int result = FAIL;
  9552. int connectorIdInt=-1;
  9553. int tempIndex = 0;
  9554. int connectorIdIsNULL, chargingProfileIsNULL;
  9555. char comfirmstr[20]={0};
  9556. char cmdBuf[512];
  9557. json_object *RemoteStartTransaction;
  9558. FILE *fp;
  9559. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9560. if(server_pending == TRUE)
  9561. {
  9562. return 0;
  9563. }
  9564. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9565. RemoteStartTransaction = json_tokener_parse(payload);
  9566. if(!is_error(RemoteStartTransaction))
  9567. {
  9568. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9569. {
  9570. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9571. }
  9572. else
  9573. {
  9574. connectorIdIsNULL = TRUE;
  9575. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9576. {
  9577. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9578. {
  9579. connectorIdIsNULL = FALSE;
  9580. connectorIdInt = (gun_index+1);
  9581. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9582. break;
  9583. }
  9584. }
  9585. }
  9586. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9587. {
  9588. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9589. // Required data
  9590. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9591. // Optional data
  9592. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9593. {
  9594. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9595. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9596. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9597. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9598. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9599. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9600. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9601. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9603. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9604. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9605. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9606. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9607. {
  9608. 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")));
  9609. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9610. 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"));
  9611. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9612. 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"));
  9613. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9614. 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")));
  9615. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9616. {
  9617. 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++)
  9618. {
  9619. 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"));
  9620. 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"));
  9621. 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)
  9622. 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"));
  9623. }
  9624. }
  9625. }
  9626. }
  9627. else
  9628. {
  9629. chargingProfileIsNULL = TRUE;
  9630. }
  9631. }
  9632. }
  9633. else
  9634. {
  9635. connectorIdIsNULL = TRUE;
  9636. }
  9637. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9638. {
  9639. DEBUG_WARN("Connector id is NULL\n.");
  9640. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9641. goto end;
  9642. }
  9643. /*
  9644. enum _SYSTEM_STATUS
  9645. {
  9646. S_BOOTING = 0,
  9647. S_IDLE, = 1
  9648. S_AUTHORIZING, = 2
  9649. S_REASSIGN_CHECK, = 3
  9650. S_REASSIGN, = 4
  9651. S_PRECHARGE, = 5
  9652. S_PREPARING_FOR_EV, = 6
  9653. S_PREPARING_FOR_EVSE, = 7
  9654. S_CHARGING, = 8
  9655. S_TERMINATING, = 9
  9656. S_COMPLETE, = 10
  9657. S_ALARM, = 11
  9658. S_FAULT = 12
  9659. }
  9660. */
  9661. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9662. {
  9663. //check Transaction active
  9664. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9665. {
  9666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9667. {
  9668. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9669. }
  9670. else
  9671. {
  9672. tempIndex = connectorIdInt -1;
  9673. }
  9674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9675. {
  9676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9677. {
  9678. 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))
  9679. {
  9680. //Reserved
  9681. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9682. }
  9683. 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))
  9684. {
  9685. //Reserved
  9686. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9688. goto end;
  9689. }
  9690. else
  9691. {
  9692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9696. {
  9697. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9699. goto end;
  9700. }
  9701. }//END FOR ELSE
  9702. }
  9703. }// END FOR CHAdeMO_QUANTITY
  9704. }
  9705. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9706. {
  9707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9708. {
  9709. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9710. }
  9711. else
  9712. {
  9713. tempIndex = connectorIdInt -1;
  9714. }
  9715. for (int index = 0; index < CCS_QUANTITY; index++)
  9716. {
  9717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9718. {
  9719. 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))
  9720. {
  9721. //Reserved
  9722. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9723. }
  9724. 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))
  9725. {
  9726. //Reserved
  9727. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9729. goto end;
  9730. }
  9731. else
  9732. {
  9733. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9734. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9735. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9736. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9737. {
  9738. DEBUG_WARN("CCS connector not allow start\n.");
  9739. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9740. goto end;
  9741. }
  9742. }// END FOR ELSE
  9743. }
  9744. }// END FOR CCS_QUANTITY
  9745. }
  9746. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9747. {
  9748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9749. {
  9750. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9751. }
  9752. else
  9753. {
  9754. tempIndex = connectorIdInt -1;
  9755. }
  9756. for (int index = 0; index < GB_QUANTITY; index++)
  9757. {
  9758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9759. {
  9760. 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))
  9761. {
  9762. //Reserved
  9763. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9764. }
  9765. 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))
  9766. {
  9767. //Reserved
  9768. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9770. goto end;
  9771. }
  9772. else
  9773. {
  9774. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9775. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9776. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9778. {
  9779. DEBUG_WARN("GB connector not allow start\n.");
  9780. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9781. goto end;
  9782. }
  9783. }// END FOR ELSE
  9784. }
  9785. } // END FOR GB_QUANTITY
  9786. }
  9787. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9788. {
  9789. tempIndex = connectorIdInt -1;
  9790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9791. {
  9792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9793. {
  9794. 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))
  9795. {
  9796. //Reserved
  9797. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9798. }
  9799. 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))
  9800. {
  9801. //Reserved
  9802. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9803. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9804. goto end;
  9805. }
  9806. else
  9807. {
  9808. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9809. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9810. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9811. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9812. {
  9813. DEBUG_WARN("GB connector not allow start\n.");
  9814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9815. goto end;
  9816. }
  9817. }// END FOR ELSE
  9818. }
  9819. } // END FOR GB_QUANTITY
  9820. }
  9821. else
  9822. {
  9823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9824. {
  9825. tempIndex = 2;
  9826. }
  9827. else
  9828. {
  9829. tempIndex = connectorIdInt -1;
  9830. }
  9831. for (int index = 0; index < AC_QUANTITY; index++)
  9832. {
  9833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9834. {
  9835. 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))
  9836. {
  9837. //Reserved
  9838. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9839. }
  9840. 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))
  9841. {
  9842. //Reserved
  9843. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9844. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9845. goto end;
  9846. }
  9847. else
  9848. {
  9849. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9850. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9851. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9852. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9853. {
  9854. DEBUG_WARN("AC connector not allow start\n.");
  9855. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9856. goto end;
  9857. }
  9858. }//END FOR ELSE
  9859. }
  9860. }// END FOR AC_QUANTITY
  9861. }
  9862. if(chargingProfileIsNULL == FALSE)
  9863. {
  9864. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9865. {
  9866. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9867. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9868. //memset idTag
  9869. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9870. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9871. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9873. // Save profile to file
  9874. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9875. system(cmdBuf);
  9876. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9877. fp = fopen(cmdBuf, "w");
  9878. 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));
  9879. fclose(fp);
  9880. }
  9881. else
  9882. {
  9883. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9884. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9885. }
  9886. }
  9887. else
  9888. {
  9889. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9890. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9891. //memset idTag
  9892. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9893. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9894. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9896. }
  9897. }
  9898. else
  9899. {
  9900. DEBUG_WARN("Connector id over\n.");
  9901. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9902. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9903. }
  9904. end:
  9905. json_object_put(RemoteStartTransaction);
  9906. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9907. {
  9908. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9909. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9910. }
  9911. //OCPP send RemoteStartConfirmation by first.
  9912. sendRemoteStartConfirmation(uuid, comfirmstr);
  9913. return result;
  9914. }
  9915. int handleRemoteStartRequest(char *uuid, char *payload)
  9916. {
  9917. mtrace();
  9918. int result = PASS;
  9919. int connectorIdInt=-1;
  9920. int tempIndex = 0;
  9921. char comfirmstr[20]={0};
  9922. char cmdBuf[512];
  9923. json_object *RemoteStartTransaction;
  9924. FILE *fp;
  9925. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9926. if(server_pending == TRUE)
  9927. {
  9928. result = FAIL;
  9929. }
  9930. RemoteStartTransaction = json_tokener_parse(payload);
  9931. if(!is_error(RemoteStartTransaction))
  9932. {
  9933. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9934. {
  9935. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9936. }
  9937. else
  9938. {
  9939. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9940. {
  9941. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9942. {
  9943. connectorIdInt = (gun_index+1);
  9944. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9945. break;
  9946. }
  9947. }
  9948. }
  9949. if(connectorIdInt == 0)
  9950. {
  9951. DEBUG_WARN("Connector id shall not equal 0.\n");
  9952. result = FAIL;
  9953. }
  9954. else if(connectorIdInt == -1)
  9955. {
  9956. DEBUG_INFO("Connector id does not specific.\n");
  9957. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9958. {
  9959. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9960. // Required data
  9961. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9962. // Optional data
  9963. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9964. {
  9965. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9966. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9967. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9968. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9969. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9970. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9971. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9972. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9973. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9974. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9975. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9976. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9977. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9978. {
  9979. 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")));
  9980. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9981. 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"));
  9982. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9983. 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"));
  9984. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9985. 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")));
  9986. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9987. {
  9988. 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++)
  9989. {
  9990. 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"));
  9991. 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"));
  9992. 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)
  9993. 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"));
  9994. }
  9995. }
  9996. }
  9997. }
  9998. else
  9999. {
  10000. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10001. }
  10002. }
  10003. }
  10004. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10005. {
  10006. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10007. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10008. // Required data
  10009. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10010. // Optional data
  10011. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10012. {
  10013. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10014. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10015. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10016. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10018. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10020. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10022. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10024. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10026. {
  10027. 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")));
  10028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10029. 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"));
  10030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10031. 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"));
  10032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10033. 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")));
  10034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10035. {
  10036. 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++)
  10037. {
  10038. 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"));
  10039. 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"));
  10040. 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)
  10041. 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"));
  10042. }
  10043. }
  10044. }
  10045. }
  10046. else
  10047. {
  10048. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10049. }
  10050. }
  10051. else
  10052. {
  10053. DEBUG_WARN("Connector id is over maximun value.\n");
  10054. result = FAIL;
  10055. }
  10056. }
  10057. if(result == PASS)
  10058. {
  10059. if(connectorIdInt > 0)
  10060. {
  10061. //check Transaction active
  10062. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10063. {
  10064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10065. {
  10066. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10067. }
  10068. else
  10069. {
  10070. tempIndex = connectorIdInt -1;
  10071. }
  10072. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10073. {
  10074. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10075. {
  10076. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10077. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10078. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10079. {
  10080. //Reserved
  10081. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10082. }
  10083. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10085. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10086. {
  10087. //Reserved
  10088. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10090. goto end;
  10091. }
  10092. else
  10093. {
  10094. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10098. {
  10099. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10101. goto end;
  10102. }
  10103. }//END FOR ELSE
  10104. }
  10105. }// END FOR CHAdeMO_QUANTITY
  10106. }
  10107. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10108. {
  10109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10110. {
  10111. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10112. }
  10113. else
  10114. {
  10115. tempIndex = connectorIdInt -1;
  10116. }
  10117. for (int index = 0; index < CCS_QUANTITY; index++)
  10118. {
  10119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10120. {
  10121. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10122. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10123. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10124. {
  10125. //Reserved
  10126. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10127. }
  10128. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10129. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10130. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10131. {
  10132. //Reserved
  10133. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10135. goto end;
  10136. }
  10137. else
  10138. {
  10139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10140. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10141. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10142. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10143. {
  10144. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10145. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10146. goto end;
  10147. }
  10148. }// END FOR ELSE
  10149. }
  10150. }// END FOR CCS_QUANTITY
  10151. }
  10152. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10153. {
  10154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10155. {
  10156. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10157. }
  10158. else
  10159. {
  10160. tempIndex = connectorIdInt -1;
  10161. }
  10162. for (int index = 0; index < GB_QUANTITY; index++)
  10163. {
  10164. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10165. {
  10166. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10167. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10168. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10169. {
  10170. //Reserved
  10171. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10172. }
  10173. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10174. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10175. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10176. {
  10177. //Reserved
  10178. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10180. goto end;
  10181. }
  10182. else
  10183. {
  10184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10185. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10186. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10187. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10188. {
  10189. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10191. goto end;
  10192. }
  10193. }// END FOR ELSE
  10194. }
  10195. } // END FOR GB_QUANTITY
  10196. }
  10197. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10198. {
  10199. tempIndex = connectorIdInt -1;
  10200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10201. {
  10202. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10203. {
  10204. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10205. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10206. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10207. {
  10208. //Reserved
  10209. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10210. }
  10211. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10213. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10214. {
  10215. //Reserved
  10216. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10217. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10218. goto end;
  10219. }
  10220. else
  10221. {
  10222. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10223. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10224. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10225. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10226. {
  10227. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10228. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10229. goto end;
  10230. }
  10231. }// END FOR ELSE
  10232. }
  10233. } // END FOR GB_QUANTITY
  10234. }
  10235. else
  10236. {
  10237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10238. {
  10239. tempIndex = 2;
  10240. }
  10241. else
  10242. {
  10243. tempIndex = connectorIdInt -1;
  10244. }
  10245. for (int index = 0; index < AC_QUANTITY; index++)
  10246. {
  10247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10248. {
  10249. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10250. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10251. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10252. {
  10253. //Reserved
  10254. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10255. }
  10256. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10258. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10259. {
  10260. //Reserved
  10261. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10263. goto end;
  10264. }
  10265. else
  10266. {
  10267. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10268. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10269. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10270. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10271. {
  10272. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10274. goto end;
  10275. }
  10276. }//END FOR ELSE
  10277. }
  10278. }// END FOR AC_QUANTITY
  10279. }
  10280. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10281. {
  10282. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10283. {
  10284. // Save profile to file
  10285. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10286. system(cmdBuf);
  10287. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10288. fp = fopen(cmdBuf, "w");
  10289. 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));
  10290. fclose(fp);
  10291. }
  10292. else
  10293. {
  10294. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10296. goto end;
  10297. }
  10298. }
  10299. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10301. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10302. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10303. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10305. }
  10306. else
  10307. {
  10308. uint8_t isHasIdleConnector = FALSE;
  10309. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10310. {
  10311. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10312. {
  10313. isHasIdleConnector = TRUE;
  10314. break;
  10315. }
  10316. }
  10317. if(isHasIdleConnector == TRUE)
  10318. {
  10319. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10320. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10321. {
  10322. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10323. {
  10324. // Save profile to file
  10325. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10326. system(cmdBuf);
  10327. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10328. fp = fopen(cmdBuf, "w");
  10329. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10330. fclose(fp);
  10331. refreshStartTimer(&clientTime.RemoteStartWait);
  10332. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10333. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10334. }
  10335. else
  10336. {
  10337. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10339. }
  10340. }
  10341. }
  10342. else
  10343. {
  10344. DEBUG_INFO("There is not any connector is idle.\n");
  10345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10346. }
  10347. }
  10348. }
  10349. else
  10350. {
  10351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10352. }
  10353. end:
  10354. json_object_put(RemoteStartTransaction);
  10355. sendRemoteStartConfirmation(uuid, comfirmstr);
  10356. return result;
  10357. }
  10358. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10359. {
  10360. mtrace();
  10361. int result = FAIL;
  10362. int match = FALSE;
  10363. int GunNO = 0;
  10364. int tempIndex = 0;
  10365. int transactionIdInt=0;
  10366. int transactionIdIsNULL= TRUE;
  10367. char comfirmstr[20];
  10368. json_object *RemoteStopTransaction;
  10369. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10370. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10371. if(server_pending == TRUE)
  10372. {
  10373. return 0;
  10374. }
  10375. RemoteStopTransaction = json_tokener_parse(payload);
  10376. if(!is_error(RemoteStopTransaction))
  10377. {
  10378. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10379. {
  10380. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10381. transactionIdIsNULL = FALSE;
  10382. }
  10383. }
  10384. json_object_put(RemoteStopTransaction);
  10385. if(transactionIdIsNULL == FALSE)
  10386. {
  10387. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10388. {
  10389. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10390. {
  10391. //check Transaction active
  10392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10393. {
  10394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10395. {
  10396. tempIndex = ((gun_index==2) ? 1: 0);
  10397. }
  10398. else
  10399. {
  10400. tempIndex = gun_index;
  10401. }
  10402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10403. {
  10404. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10405. {
  10406. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10407. {
  10408. match = TRUE;
  10409. GunNO = gun_index;
  10410. }
  10411. }
  10412. }// END FOR CHAdeMO_QUANTITY
  10413. }
  10414. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10415. {
  10416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10417. {
  10418. tempIndex = ((gun_index==2) ? 1: 0);
  10419. }
  10420. else
  10421. {
  10422. tempIndex = gun_index;
  10423. }
  10424. for (int index = 0; index < CCS_QUANTITY; index++)
  10425. {
  10426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10427. {
  10428. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10429. {
  10430. match = TRUE;
  10431. GunNO = gun_index;
  10432. }
  10433. }
  10434. }// END FOR CCS_QUANTITY
  10435. }
  10436. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10437. {
  10438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10439. {
  10440. tempIndex = ((gun_index==2) ? 1: 0);
  10441. }
  10442. else
  10443. {
  10444. tempIndex = gun_index;
  10445. }
  10446. for (int index = 0; index < GB_QUANTITY; index++)
  10447. {
  10448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10449. {
  10450. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10451. {
  10452. match = TRUE;
  10453. GunNO = gun_index;
  10454. }
  10455. }
  10456. }// END FOR GB_QUANTITY
  10457. }
  10458. else if(gunType[gun_index] == GUN_TYPE_DO)
  10459. {
  10460. tempIndex = gun_index;
  10461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10462. {
  10463. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10464. {
  10465. 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
  10466. {
  10467. match = TRUE;
  10468. GunNO = gun_index;
  10469. }
  10470. }
  10471. }// END FOR GB_QUANTITY
  10472. }
  10473. else
  10474. {
  10475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10476. {
  10477. tempIndex = 2;
  10478. }
  10479. else
  10480. {
  10481. tempIndex = gun_index;
  10482. }
  10483. for (int index = 0; index < AC_QUANTITY; index++)
  10484. {
  10485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10486. {
  10487. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10488. {
  10489. match = TRUE;
  10490. GunNO = gun_index;
  10491. }
  10492. }
  10493. }// END FOR CHAdeMO_QUANTITY
  10494. } // END FOR AC ELSE
  10495. }// CHECK IF ResponseTransactionId == transactionIdInt
  10496. }//END FOR
  10497. if( match == TRUE)
  10498. {
  10499. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10501. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10502. }
  10503. else
  10504. {
  10505. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10506. }
  10507. }
  10508. else
  10509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10510. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10511. return result;
  10512. }
  10513. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10514. {
  10515. mtrace();
  10516. int result = FAIL;
  10517. int connectorIdInt=0, reservationIdInt=0;
  10518. int tempIndex = 0;
  10519. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10520. char comfirmstr[20]={0};
  10521. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10522. int c = 0;
  10523. char *loc;
  10524. //char *ptr;
  10525. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10526. strcpy(sstrtemp, stringtrimspace(payload));
  10527. //***(1)connectorId ****/
  10528. c=0;
  10529. loc = strstr(sstrtemp, "connectorId");
  10530. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10531. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10532. {
  10533. sstr[c] = loc[strlen("connectorId")+2+c];
  10534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10535. c++;
  10536. }
  10537. sstr[c] = '\0';
  10538. connectorIdInt = atoi(sstr);
  10539. //***(2)expiryDate ****/
  10540. loc = strstr(sstrtemp, "expiryDate");
  10541. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10542. c = 0;
  10543. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10544. {
  10545. sstr[c] = loc[3+strlen("expiryDate")+c];
  10546. c++;
  10547. }
  10548. sstr[c] = '\0';
  10549. strcpy(expiryDatestr, sstr);
  10550. //***(3)idTag ****/
  10551. loc = strstr(sstrtemp, "idTag");
  10552. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10553. c = 0;
  10554. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10555. {
  10556. sstr[c] = loc[3+strlen("idTag")+c];
  10557. c++;
  10558. }
  10559. sstr[c] = '\0';
  10560. strcpy(idTagstr, sstr);
  10561. //***(4)parentIdTag ****/
  10562. loc = strstr(sstrtemp, "parentIdTag");
  10563. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10564. c = 0;
  10565. if(loc == NULL)
  10566. {
  10567. strcpy(parentIdTagstr, "");
  10568. }
  10569. else
  10570. {
  10571. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10572. {
  10573. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10574. c++;
  10575. }
  10576. sstr[c] = '\0';
  10577. strcpy(parentIdTagstr, sstr);
  10578. }
  10579. //***(5)reservationId ****/
  10580. c=0;
  10581. loc = strstr(sstrtemp, "reservationId");
  10582. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10583. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10584. {
  10585. sstr[c] = loc[strlen("reservationId")+2+c];
  10586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10587. c++;
  10588. }
  10589. sstr[c] = '\0';
  10590. reservationIdInt = atoi(sstr);
  10591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10592. /*
  10593. enum SYSTEM_STATUS
  10594. {
  10595. SYS_MODE_BOOTING = 0,
  10596. SYS_MODE_IDLE = 1,
  10597. SYS_MODE_AUTHORIZING = 2,
  10598. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10599. SYS_MODE_REASSIGN = 4,
  10600. SYS_MODE_PREPARING = 5,
  10601. SYS_MODE_PREPARE_FOR_EV = 6,
  10602. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10603. SYS_MODE_CHARGING = 8,
  10604. SYS_MODE_TERMINATING = 9,
  10605. SYS_MODE_COMPLETE = 10,
  10606. SYS_MODE_ALARM = 11,
  10607. SYS_MODE_FAULT = 12,
  10608. SYS_MODE_RESERVATION = 13,
  10609. SYS_MODE_BOOKING = 14,
  10610. SYS_MODE_MAINTAIN = 15,
  10611. SYS_MODE_DEBUG = 16,
  10612. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10613. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10614. SYS_MODE_UPDATE = 19
  10615. };
  10616. */
  10617. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10618. {
  10619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10620. goto end;
  10621. }
  10622. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10623. {
  10624. //check Transaction active
  10625. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10626. {
  10627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10628. {
  10629. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10630. }
  10631. else
  10632. {
  10633. tempIndex = connectorIdInt -1;
  10634. }
  10635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10636. {
  10637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10638. {
  10639. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10640. {
  10641. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10642. {
  10643. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10644. {
  10645. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10647. }
  10648. 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'))
  10649. {
  10650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10651. }
  10652. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10653. {
  10654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10655. }
  10656. else
  10657. {
  10658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10659. }
  10660. }
  10661. 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
  10662. {
  10663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10664. }
  10665. }
  10666. else
  10667. {
  10668. //replace reservation
  10669. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10671. }
  10672. }
  10673. } // END FOR CHAdeMO_QUANTITY
  10674. }
  10675. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10676. {
  10677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10678. {
  10679. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10680. }
  10681. else
  10682. {
  10683. tempIndex = connectorIdInt -1;
  10684. }
  10685. for (int index = 0; index < CCS_QUANTITY; index++)
  10686. {
  10687. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10688. {
  10689. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10690. {
  10691. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10693. {
  10694. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10695. {
  10696. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10698. }
  10699. 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'))
  10700. {
  10701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10702. }
  10703. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10704. {
  10705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10706. }
  10707. else
  10708. {
  10709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10710. }
  10711. }
  10712. 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
  10713. {
  10714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10715. }
  10716. }
  10717. else
  10718. {
  10719. //replace reservation
  10720. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10722. }
  10723. }
  10724. } // END FOR CCS_QUANTITY
  10725. }
  10726. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10727. {
  10728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10729. {
  10730. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10731. }
  10732. else
  10733. {
  10734. tempIndex = connectorIdInt -1;
  10735. }
  10736. for (int index = 0; index < GB_QUANTITY; index++)
  10737. {
  10738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10739. {
  10740. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10741. {
  10742. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10743. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10744. {
  10745. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10746. {
  10747. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10749. }
  10750. 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'))
  10751. {
  10752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10753. }
  10754. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10755. {
  10756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10757. }
  10758. else
  10759. {
  10760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10761. }
  10762. }
  10763. 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
  10764. {
  10765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10766. }
  10767. }
  10768. else
  10769. {
  10770. //replace reservation
  10771. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10773. }
  10774. }
  10775. }// END FOR GB_QUANTITY
  10776. }
  10777. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10778. {
  10779. tempIndex = connectorIdInt -1;
  10780. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10781. {
  10782. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10783. {
  10784. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10785. {
  10786. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10787. 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
  10788. {
  10789. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10790. {
  10791. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10793. }
  10794. 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'))
  10795. {
  10796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10797. }
  10798. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10799. {
  10800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10801. }
  10802. else
  10803. {
  10804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10805. }
  10806. }
  10807. 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
  10808. {
  10809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10810. }
  10811. }
  10812. else
  10813. {
  10814. //replace reservation
  10815. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10817. }
  10818. }
  10819. }// END FOR GB_QUANTITY
  10820. }
  10821. else
  10822. {
  10823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10824. {
  10825. tempIndex = 2;
  10826. }
  10827. else
  10828. {
  10829. tempIndex = (connectorIdInt -1);
  10830. }
  10831. for (int index = 0; index < AC_QUANTITY; index++)
  10832. {
  10833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10834. {
  10835. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10838. {
  10839. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10840. {
  10841. 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))
  10842. {
  10843. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10844. }
  10845. else
  10846. {
  10847. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10849. }
  10850. }
  10851. 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'))
  10852. {
  10853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10854. }
  10855. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10856. {
  10857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10858. }
  10859. else
  10860. {
  10861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10862. }
  10863. }
  10864. 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
  10865. {
  10866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10867. }
  10868. }
  10869. else
  10870. {
  10871. //replace reservation
  10872. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10874. }
  10875. }
  10876. } // END FOR AC_QUANTITY
  10877. }
  10878. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10879. }
  10880. else if(connectorIdInt == 0)
  10881. {
  10882. //check Transaction active
  10883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10884. {
  10885. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10886. {
  10887. 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'))
  10888. {
  10889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10890. goto end;
  10891. }
  10892. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10893. {
  10894. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10895. goto end;
  10896. }
  10897. 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
  10898. {
  10899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10900. goto end;
  10901. }
  10902. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10903. {
  10904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10905. goto end;
  10906. }
  10907. }
  10908. }// END FOR CHAdeMO_QUANTITY
  10909. for (int index = 0; index < CCS_QUANTITY; index++)
  10910. {
  10911. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10912. {
  10913. 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'))
  10914. {
  10915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10916. goto end;
  10917. }
  10918. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10919. {
  10920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10921. goto end;
  10922. }
  10923. 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
  10924. {
  10925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10926. goto end;
  10927. }
  10928. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10929. {
  10930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10931. goto end;
  10932. }
  10933. }
  10934. } // END FOR CCS_QUANTITY
  10935. for (int index = 0; index < GB_QUANTITY; index++)
  10936. {
  10937. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10938. {
  10939. 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'))
  10940. {
  10941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10942. goto end;
  10943. }
  10944. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10945. {
  10946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10947. goto end;
  10948. }
  10949. 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
  10950. {
  10951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10952. goto end;
  10953. }
  10954. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10955. {
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10957. goto end;
  10958. }
  10959. }
  10960. } // END FOR GB_QUANTITY
  10961. for (int index = 0; index < AC_QUANTITY; index++)
  10962. {
  10963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10964. {
  10965. 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'))
  10966. {
  10967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10968. goto end;
  10969. }
  10970. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10971. {
  10972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10973. goto end;
  10974. }
  10975. 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
  10976. {
  10977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10978. goto end;
  10979. }
  10980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10981. {
  10982. 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))
  10983. {
  10984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10985. goto end;
  10986. }
  10987. }
  10988. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10989. {
  10990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10991. goto end;
  10992. }
  10993. }
  10994. }// END FOR AC_QUANTITY
  10995. //The connectorId is 0
  10996. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10998. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10999. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11000. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11001. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11002. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11003. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11004. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11005. result = TRUE;
  11006. return result;
  11007. }
  11008. else
  11009. {
  11010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11011. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11012. }
  11013. if(strcmp(comfirmstr,"Accepted") == 0)
  11014. {
  11015. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11016. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11017. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11018. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11019. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11020. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11021. result = TRUE;
  11022. return result;
  11023. }
  11024. end:
  11025. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11026. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11027. return result;
  11028. }
  11029. int handleResetRequest(char *uuid, char *payload)
  11030. {
  11031. mtrace();
  11032. int result = FAIL;
  11033. char sstr[10]={0},sstrtemp[30]={ 0 };
  11034. char typestr[10]={0};
  11035. char comfirmstr[20]={0};
  11036. int c = 0;
  11037. char *loc;
  11038. DEBUG_INFO("handleResetRequest...\n");
  11039. strcpy(sstrtemp, stringtrimspace(payload));
  11040. loc = strstr(sstrtemp, "type");
  11041. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11042. c = 0;
  11043. while (loc[3+strlen("type")+c] != '\"')
  11044. {
  11045. sstr[c] = loc[3+strlen("type")+c];
  11046. c++;
  11047. }
  11048. sstr[c] = '\0';
  11049. strcpy(typestr,sstr);
  11050. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11051. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11052. {
  11053. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11054. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11055. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11056. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11057. }
  11058. else
  11059. {
  11060. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11061. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11062. result = PASS;
  11063. }
  11064. sendResetConfirmation(uuid, comfirmstr);
  11065. return result;
  11066. }
  11067. int handleSendLocalListRequest(char *uuid, char *payload)
  11068. {
  11069. mtrace();
  11070. int result = FAIL;
  11071. char comfirmstr[20];
  11072. int checkState_Faulted = FALSE;
  11073. json_object *SendLocalList;
  11074. DEBUG_INFO("handleSendLocalListRequest...\n");
  11075. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11076. {
  11077. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11078. goto end;
  11079. }
  11080. //check Charge Point state
  11081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11082. {
  11083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11084. {
  11085. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11086. }
  11087. }
  11088. for (int index = 0; index < CCS_QUANTITY; index++)
  11089. {
  11090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11091. {
  11092. checkState_Faulted = TRUE; //OCPP Status
  11093. }
  11094. }
  11095. for (int index = 0; index < GB_QUANTITY; index++)
  11096. {
  11097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11098. {
  11099. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11100. }
  11101. }
  11102. //check Charge Point state
  11103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11104. {
  11105. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11106. {
  11107. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11108. }
  11109. }
  11110. //check Charge Point state
  11111. for (int index = 0; index < AC_QUANTITY; index++)
  11112. {
  11113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11114. {
  11115. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11116. }
  11117. }
  11118. if(checkState_Faulted == TRUE)
  11119. {
  11120. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11121. goto end;
  11122. }
  11123. // Parsing payload
  11124. SendLocalList = json_tokener_parse(payload);
  11125. if(!is_error(SendLocalList))
  11126. {
  11127. // Required data
  11128. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11129. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11130. // Optional data
  11131. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11132. {
  11133. //Check UpdateType
  11134. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11135. {
  11136. //Local list full update
  11137. DEBUG_INFO("Local list full update.\n");
  11138. OCPP_getListVerion();
  11139. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11140. {
  11141. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11142. goto end;
  11143. }
  11144. OCPP_cleanLocalList();
  11145. }
  11146. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11147. {
  11148. //Local list different update
  11149. DEBUG_INFO("Local list different update.\n");
  11150. OCPP_getListVerion();
  11151. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11152. {
  11153. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11154. goto end;
  11155. }
  11156. }
  11157. else
  11158. {
  11159. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11160. goto end;
  11161. }
  11162. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11163. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11164. {
  11165. 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")));
  11166. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11167. {
  11168. 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")));
  11169. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11170. 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")));
  11171. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11172. 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")));
  11173. }
  11174. // Add to db
  11175. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11176. {
  11177. //Local list full update
  11178. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11179. idx,
  11180. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11181. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11182. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11183. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11184. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11185. // update list
  11186. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11187. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11188. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11189. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11190. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11191. }
  11192. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11193. {
  11194. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11195. idx,
  11196. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11197. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11198. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11199. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11200. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11201. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11202. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11203. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11204. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11205. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11206. }
  11207. }
  11208. }
  11209. else
  11210. {
  11211. //Check UpdateType
  11212. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11213. {
  11214. //Local list full update
  11215. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11216. OCPP_cleanLocalList();
  11217. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11218. goto end;
  11219. }
  11220. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11221. {
  11222. //Local list different update
  11223. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11224. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11225. goto end;
  11226. }
  11227. }
  11228. result = PASS;
  11229. }
  11230. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11231. end:
  11232. json_object_put(SendLocalList);
  11233. sendSendLocalListConfirmation(uuid, comfirmstr);
  11234. return result;
  11235. }
  11236. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11237. {
  11238. mtrace();
  11239. int result = FAIL;
  11240. struct StructSetChargingProfile SetProfileReq = {0};
  11241. int tempchargingProfileIdInt;
  11242. int chargingSchedulePeriodCount = 0;
  11243. char comfirmstr[20]={0};
  11244. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11245. char rmFileCmd[128]={0};
  11246. int profileQuantity = 0;
  11247. json_object *SetChargingProfile;
  11248. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11249. SetChargingProfile = json_tokener_parse(payload);
  11250. if(!is_error(SetChargingProfile))
  11251. {
  11252. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11253. {
  11254. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11255. }
  11256. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11257. {
  11258. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11259. {
  11260. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11261. }
  11262. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11263. {
  11264. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11265. }
  11266. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11267. {
  11268. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11269. }
  11270. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11271. {
  11272. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11273. }
  11274. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11275. {
  11276. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11277. }
  11278. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11279. {
  11280. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11281. }
  11282. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11283. {
  11284. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11285. }
  11286. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11287. {
  11288. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11289. }
  11290. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11291. {
  11292. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11293. {
  11294. 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")));
  11295. }
  11296. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11297. {
  11298. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11299. }
  11300. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11301. {
  11302. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11303. }
  11304. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11305. {
  11306. 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")));
  11307. }
  11308. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11309. {
  11310. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11311. if(chargingSchedulePeriodCount <= 10)
  11312. {
  11313. 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++)
  11314. {
  11315. 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)
  11316. {
  11317. 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"));
  11318. }
  11319. 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)
  11320. {
  11321. 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"));
  11322. }
  11323. 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)
  11324. {
  11325. 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"));
  11326. }
  11327. }
  11328. }
  11329. }
  11330. }
  11331. }
  11332. }
  11333. // Profile periods quantity check
  11334. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11335. {
  11336. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11337. goto end;
  11338. }
  11339. // Check invalid limit
  11340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11341. {
  11342. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11343. {
  11344. 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)))) ||
  11345. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11346. {
  11347. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11348. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11349. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11350. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11351. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11352. goto end;
  11353. }
  11354. }
  11355. }
  11356. else
  11357. {
  11358. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11359. {
  11360. 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))
  11361. {
  11362. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11363. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11364. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11365. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11366. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11367. goto end;
  11368. }
  11369. }
  11370. }
  11371. // Profile purpose info check
  11372. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11373. {
  11374. FILE *fp;
  11375. char dataLine[4096]={0};
  11376. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11377. if(SetProfileReq.ConnectorId != 0)
  11378. {
  11379. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11380. goto end;
  11381. }
  11382. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11383. if (!fp)
  11384. {
  11385. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11386. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11387. }
  11388. else
  11389. {
  11390. while(fscanf(fp, "%s", dataLine) != EOF)
  11391. {
  11392. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11393. {
  11394. profileQuantity += 1;
  11395. }
  11396. }
  11397. }
  11398. fclose(fp);
  11399. }
  11400. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11401. {
  11402. FILE *fp;
  11403. char dataLine[4096]={0};
  11404. char filename[128]={0};
  11405. int tmpProfileQuantity;
  11406. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11407. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11408. {
  11409. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11410. goto end;
  11411. }
  11412. if(SetProfileReq.ConnectorId == 0)
  11413. {
  11414. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11415. {
  11416. tmpProfileQuantity = 0;
  11417. memset(filename, 0, ARRAY_SIZE(filename));
  11418. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11419. fp = fopen(filename, "r");
  11420. if (!fp)
  11421. {
  11422. DEBUG_INFO("%s does not create.\n", filename);
  11423. fp = fopen(filename, "w+");
  11424. }
  11425. else
  11426. {
  11427. while(fscanf(fp, "%s", dataLine) != EOF)
  11428. {
  11429. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11430. {
  11431. tmpProfileQuantity += 1;
  11432. }
  11433. }
  11434. }
  11435. fclose(fp);
  11436. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11437. }
  11438. }
  11439. else
  11440. {
  11441. memset(filename, 0, ARRAY_SIZE(filename));
  11442. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11443. fp = fopen(filename, "r");
  11444. if (!fp)
  11445. {
  11446. DEBUG_INFO("%s does not create.\n", filename);
  11447. fp = fopen(filename, "w+");
  11448. }
  11449. else
  11450. {
  11451. while(fscanf(fp, "%s", dataLine) != EOF)
  11452. {
  11453. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11454. {
  11455. profileQuantity += 1;
  11456. }
  11457. }
  11458. }
  11459. fclose(fp);
  11460. }
  11461. }
  11462. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11463. {
  11464. int isMatchTransactiodId= FALSE;
  11465. FILE *fp;
  11466. char dataLine[4096]={0};
  11467. char filename[128]={0};
  11468. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11469. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11470. if(SetProfileReq.ConnectorId == 0)
  11471. {
  11472. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11473. goto end;
  11474. }
  11475. int tempIndex = 0;
  11476. //check Transaction active
  11477. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11478. {
  11479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11480. {
  11481. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11482. }
  11483. else
  11484. {
  11485. tempIndex = SetProfileReq.ConnectorId -1;
  11486. }
  11487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11488. {
  11489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11490. {
  11491. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11492. {
  11493. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11494. {
  11495. isMatchTransactiodId = TRUE;
  11496. break;
  11497. }
  11498. }
  11499. }
  11500. }
  11501. }
  11502. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11503. {
  11504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11505. {
  11506. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11507. }
  11508. else
  11509. {
  11510. tempIndex = SetProfileReq.ConnectorId -1;
  11511. }
  11512. for (int index = 0; index < CCS_QUANTITY; index++)
  11513. {
  11514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11515. {
  11516. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11517. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11518. {
  11519. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11520. {
  11521. isMatchTransactiodId = TRUE;
  11522. break;
  11523. }
  11524. }
  11525. }
  11526. }
  11527. }
  11528. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11529. {
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11531. {
  11532. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11533. }
  11534. else
  11535. {
  11536. tempIndex = SetProfileReq.ConnectorId -1;
  11537. }
  11538. for (int index = 0; index < GB_QUANTITY; index++)
  11539. {
  11540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11541. {
  11542. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11543. {
  11544. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11545. {
  11546. isMatchTransactiodId = TRUE;
  11547. break;
  11548. }
  11549. }
  11550. }
  11551. }
  11552. }
  11553. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11554. {
  11555. tempIndex = SetProfileReq.ConnectorId -1;
  11556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11557. {
  11558. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11559. {
  11560. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11561. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11562. {
  11563. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11564. {
  11565. isMatchTransactiodId = TRUE;
  11566. break;
  11567. }
  11568. }
  11569. }
  11570. }
  11571. }
  11572. else
  11573. {
  11574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11575. {
  11576. tempIndex = 2;
  11577. }
  11578. else
  11579. {
  11580. tempIndex = (SetProfileReq.ConnectorId -1);
  11581. }
  11582. for (int index = 0; index < AC_QUANTITY; index++)
  11583. {
  11584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11585. {
  11586. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11587. {
  11588. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11589. {
  11590. isMatchTransactiodId = TRUE;
  11591. break;
  11592. }
  11593. }
  11594. }
  11595. }
  11596. }
  11597. //check Transaction active
  11598. if(isMatchTransactiodId == FALSE)
  11599. {
  11600. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11601. goto end;
  11602. }
  11603. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11604. {
  11605. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11606. goto end;
  11607. }
  11608. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11609. fp = fopen(filename, "r");
  11610. if (!fp)
  11611. {
  11612. DEBUG_INFO("%s does not create.\n", filename);
  11613. fp = fopen(filename, "w+");
  11614. }
  11615. else
  11616. {
  11617. //Check Charging Profile Count
  11618. while(fscanf(fp, "%s", dataLine) != EOF)
  11619. {
  11620. //DEBUG_INFO("word=%s\n",word);
  11621. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11622. {
  11623. profileQuantity += 1;
  11624. }
  11625. }
  11626. }
  11627. fclose(fp);
  11628. }
  11629. // Check ChargeProfileMaxStackLevel
  11630. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11631. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11632. {
  11633. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11634. goto end;
  11635. }
  11636. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11637. {
  11638. FILE *fp;
  11639. char dataLine[4096]={0};
  11640. char fnametemp[128]={0};
  11641. int tmpProfileQuantity;
  11642. //Check ChargePointMaxProfile.json exit
  11643. profileQuantity = 0;
  11644. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11645. {
  11646. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11647. //Check Charging Profile Count
  11648. tmpProfileQuantity = 0;
  11649. while(fscanf(fp, "%s", dataLine) != EOF)
  11650. {
  11651. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11652. {
  11653. profileQuantity += 1;
  11654. tmpProfileQuantity += 1;
  11655. }
  11656. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11657. }
  11658. fclose(fp);
  11659. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11660. }
  11661. //Check TxDefaultProfile_%d.json
  11662. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11663. {
  11664. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11665. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11666. if((access(fnametemp,F_OK))!=-1)
  11667. {
  11668. fp = fopen(fnametemp, "r");
  11669. //Check Charging Profile Count
  11670. tmpProfileQuantity = 0;
  11671. while(fscanf(fp, "%s", dataLine) != EOF)
  11672. {
  11673. //DEBUG_INFO("word=%s\n",word);
  11674. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11675. {
  11676. profileQuantity += 1;
  11677. tmpProfileQuantity += 1;
  11678. }
  11679. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11680. }
  11681. fclose(fp);
  11682. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11683. }
  11684. }
  11685. //Check TxProfile_%d.json
  11686. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11687. {
  11688. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11689. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11690. if((access(fnametemp,F_OK))!=-1)
  11691. {
  11692. fp = fopen(fnametemp, "r");
  11693. //Check Charging Profile Count
  11694. tmpProfileQuantity = 0;
  11695. while(fscanf(fp, "%s", dataLine) != EOF)
  11696. {
  11697. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11698. {
  11699. profileQuantity += 1;
  11700. tmpProfileQuantity += 1;
  11701. }
  11702. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11703. }
  11704. fclose(fp);
  11705. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11706. }
  11707. }
  11708. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11709. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11710. {
  11711. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11712. goto end;
  11713. }
  11714. }
  11715. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11716. //**********************************Write to File********************************************************/
  11717. {
  11718. FILE *infile;
  11719. FILE *outfile;
  11720. char dataLine[4096]={0};
  11721. char filename[128]={0};
  11722. int chkChar=0;
  11723. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11724. {
  11725. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11726. {
  11727. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11728. }
  11729. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11730. {
  11731. if(SetProfileReq.ConnectorId==0)
  11732. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11733. else
  11734. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11735. }
  11736. else
  11737. {
  11738. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11739. }
  11740. infile = fopen (filename, "r");
  11741. outfile = fopen (tempfile, "w");
  11742. chkChar = fgetc(infile);
  11743. rewind(infile);
  11744. if(chkChar == EOF)
  11745. {
  11746. // Profile is empty
  11747. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11748. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11749. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11750. fclose(infile);
  11751. fclose(outfile);
  11752. sprintf(rmFileCmd,"rm -f %s",filename);
  11753. system(rmFileCmd);
  11754. rename(tempfile, filename);
  11755. }
  11756. else
  11757. {
  11758. // Profile is not empty
  11759. int ChargingProfileAdded = FALSE;
  11760. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11761. {
  11762. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11763. json_object *tmpChargingProfile;
  11764. tmpChargingProfile = json_tokener_parse(dataLine);
  11765. if(!is_error(SetChargingProfile))
  11766. {
  11767. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11768. {
  11769. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11770. {
  11771. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11772. }
  11773. }
  11774. }
  11775. json_object_put(tmpChargingProfile);
  11776. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11777. {
  11778. if(ChargingProfileAdded == FALSE)
  11779. {
  11780. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11781. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11782. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11783. ChargingProfileAdded = TRUE;
  11784. }
  11785. }
  11786. else
  11787. {
  11788. fprintf(outfile,"%s\n",dataLine);
  11789. if(ChargingProfileAdded == FALSE)
  11790. {
  11791. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11792. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11793. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11794. ChargingProfileAdded = TRUE;
  11795. }
  11796. }
  11797. } // end of while loop
  11798. fclose(infile);
  11799. fclose(outfile);
  11800. sprintf(rmFileCmd,"rm -f %s",filename);
  11801. system(rmFileCmd);
  11802. rename(tempfile, filename);
  11803. }
  11804. }
  11805. sleep(1);
  11806. result = TRUE;
  11807. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11808. }
  11809. end:
  11810. json_object_put(SetChargingProfile);
  11811. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11812. {
  11813. if(SetProfileReq.ConnectorId == 0)
  11814. {
  11815. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11816. {
  11817. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11818. }
  11819. }
  11820. else
  11821. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11822. }
  11823. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11824. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11825. return result;
  11826. }
  11827. int handleTriggerMessageRequest(char *uuid, char *payload)
  11828. {
  11829. mtrace();
  11830. int result = FAIL;
  11831. int connectorIdIsNULL = FALSE;
  11832. int connectorIdInt =0;
  11833. char sstr[40]={0},sstrtemp[100]={ 0 };
  11834. char requestedMessagestr[40]={0};
  11835. char comfirmstr[20]={0};
  11836. int c = 0;
  11837. char *loc;
  11838. DEBUG_INFO("handleTriggerMessageRequest\n");
  11839. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11840. strcpy(sstrtemp, stringtrimspace(payload));
  11841. c = 0;
  11842. loc = strstr(sstrtemp, "requestedMessage");
  11843. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11844. {
  11845. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11846. c++;
  11847. }
  11848. sstr[c] = '\0';
  11849. strcpy(requestedMessagestr, sstr);
  11850. c = 0;
  11851. loc = strstr(sstrtemp, "connectorId");
  11852. if(loc == NULL)
  11853. {
  11854. connectorIdIsNULL = TRUE;
  11855. }
  11856. else
  11857. {
  11858. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11859. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11860. {
  11861. sstr[c] = loc[strlen("connectorId")+2+c];
  11862. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11863. c++;
  11864. }
  11865. sstr[c] = '\0';
  11866. connectorIdInt = atoi(sstr);
  11867. }
  11868. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11869. {
  11870. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11871. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11872. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11873. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11874. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11875. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11876. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11877. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11878. {
  11879. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11880. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11881. return TRUE;
  11882. }
  11883. else
  11884. {
  11885. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11886. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11887. }
  11888. }
  11889. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11890. {
  11891. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11892. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11893. return TRUE;
  11894. }
  11895. //==========================
  11896. // Trigger message
  11897. //==========================
  11898. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11899. {
  11900. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11901. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11902. {
  11903. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11904. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11905. }
  11906. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11907. }
  11908. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11909. {
  11910. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11911. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11912. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11913. }
  11914. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11915. {
  11916. //sendBootNotificationRequest();
  11917. server_sign = FALSE;
  11918. }
  11919. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11920. {
  11921. refreshStartTimer(&clientTime.Heartbeat);
  11922. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11923. }
  11924. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11925. {
  11926. if(connectorIdIsNULL == FALSE)
  11927. {
  11928. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11929. {
  11930. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11931. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11932. }
  11933. }
  11934. else
  11935. {
  11936. for(int idx=0;idx< gunTotalNumber;idx++)
  11937. {
  11938. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11939. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11940. }
  11941. }
  11942. }
  11943. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11944. {
  11945. if(connectorIdIsNULL == FALSE)
  11946. {
  11947. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11948. {
  11949. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11950. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11951. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11952. }
  11953. }
  11954. else
  11955. {
  11956. for(int idx=0;idx< gunTotalNumber;idx++)
  11957. {
  11958. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11959. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11960. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11961. }
  11962. }
  11963. }
  11964. return result;
  11965. }
  11966. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11967. {
  11968. mtrace();
  11969. int result = FAIL;
  11970. int connectorIdInt =0;
  11971. char comfirmstr[20]={0};
  11972. int tempIndex = 0;
  11973. json_object *UnlockConnector;
  11974. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11975. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11976. UnlockConnector = json_tokener_parse(payload);
  11977. if(!is_error(UnlockConnector))
  11978. {
  11979. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11980. {
  11981. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11982. }
  11983. }
  11984. json_object_put(UnlockConnector);
  11985. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11986. if(gunTotalNumber == 0)
  11987. {
  11988. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11989. goto end;
  11990. }
  11991. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11992. {
  11993. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11994. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11995. goto end;
  11996. }
  11997. else
  11998. {
  11999. //check Transaction active
  12000. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12001. {
  12002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12003. {
  12004. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12005. }
  12006. else
  12007. {
  12008. tempIndex = connectorIdInt -1;
  12009. }
  12010. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12011. {
  12012. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12013. {
  12014. //stop Transaction
  12015. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12016. }
  12017. }
  12018. }
  12019. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12020. {
  12021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12022. {
  12023. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12024. }
  12025. else
  12026. {
  12027. tempIndex = connectorIdInt -1;
  12028. }
  12029. for (int index = 0; index < CCS_QUANTITY; index++)
  12030. {
  12031. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12032. {
  12033. //stop Transaction
  12034. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12035. }
  12036. }
  12037. }
  12038. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12039. {
  12040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12041. {
  12042. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12043. }
  12044. else
  12045. {
  12046. tempIndex = connectorIdInt -1;
  12047. }
  12048. for (int index = 0; index < GB_QUANTITY; index++)
  12049. {
  12050. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12051. {
  12052. //stop Transaction
  12053. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12054. }
  12055. }
  12056. }
  12057. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12058. {
  12059. tempIndex = connectorIdInt -1;
  12060. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12061. {
  12062. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12063. {
  12064. //stop Transaction
  12065. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12066. }
  12067. }
  12068. }
  12069. else
  12070. {
  12071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12072. {
  12073. tempIndex = 2;
  12074. }
  12075. else
  12076. {
  12077. tempIndex = connectorIdInt-1;
  12078. }
  12079. for (int index = 0; index < AC_QUANTITY; index++)
  12080. {
  12081. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12082. {
  12083. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12084. }
  12085. }
  12086. }
  12087. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12088. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12089. result = TRUE;
  12090. return result;
  12091. }
  12092. end:
  12093. //json_object_put(obj); --- remove temporally
  12094. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12095. return result;
  12096. }
  12097. static char UpdateFirmwarepayloadData[300]={0};
  12098. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12099. {
  12100. mtrace();
  12101. int result = FAIL;
  12102. pthread_t t;
  12103. sendUpdateFirmwareConfirmation(uuid);
  12104. memset(UpdateFirmwarepayloadData, 0, 300);
  12105. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12106. if(!interLock.isUpdateFirmwareGoing)
  12107. {
  12108. interLock.isUpdateFirmwareGoing = 1;
  12109. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12110. sleep(1);
  12111. }
  12112. else
  12113. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12114. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12115. return result;
  12116. }
  12117. void *UpdateFirmwareProcess(void *data)
  12118. {
  12119. pthread_detach(pthread_self());
  12120. mtrace();
  12121. int retriesInt =0, retryIntervalInt=0;
  12122. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12123. int port=0;
  12124. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12125. int isSuccess = 0;
  12126. char ftpbuf[512];
  12127. char temp[100];
  12128. char * pch;
  12129. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12130. json_object *UpdateFirmware;
  12131. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12132. if(!is_error(UpdateFirmware))
  12133. {
  12134. // Required data
  12135. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12136. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12137. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12138. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12139. // Optional data
  12140. if(json_object_object_get(UpdateFirmware, "retries"))
  12141. {
  12142. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12143. }
  12144. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12145. {
  12146. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12147. }
  12148. }
  12149. json_object_put(UpdateFirmware);
  12150. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12151. memset(path, 0, ARRAY_SIZE(path));
  12152. // Wait retrieveData
  12153. if(strlen(retrieveDatestr) > 10)
  12154. {
  12155. do
  12156. {
  12157. sleep(1);
  12158. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12159. }
  12160. // Ready to download
  12161. system("rm -f /mnt/*");
  12162. if(strncmp(locationstr,"http", 4) == 0)
  12163. {
  12164. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12165. sprintf(ftppath,"/%s", path);
  12166. DEBUG_INFO("locationstr: %s\n", locationstr);
  12167. DEBUG_INFO("protocol: %s\n",protocol);
  12168. DEBUG_INFO("host: %s\n",host);
  12169. DEBUG_INFO("path: %s\n",path);
  12170. DEBUG_INFO("ftppath: %s\n",ftppath);
  12171. int ftppathlen=strlen(ftppath);
  12172. int i=1;
  12173. char filenametemp[50];
  12174. while(i < ftppathlen)
  12175. {
  12176. int len=ftppathlen-i;
  12177. if(ftppath[len]== 47) // '/' ascll code: 47
  12178. {
  12179. DEBUG_INFO("compare '/' all right\n");
  12180. break;
  12181. }
  12182. i=i+1;
  12183. }
  12184. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12185. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12186. filenametemp[i+1] = 0;
  12187. do
  12188. {
  12189. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12190. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12191. sleep(1);
  12192. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12193. if(!isSuccess)
  12194. {
  12195. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12196. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12197. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12198. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12199. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12200. }
  12201. else
  12202. {
  12203. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12204. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12205. }
  12206. retriesInt--;
  12207. }while((isSuccess == 0)&&(retriesInt >= 0));
  12208. }
  12209. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12210. {
  12211. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12212. memset(temp, 0, ARRAY_SIZE(temp));
  12213. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12214. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12215. int ftppathlen=strlen(ftpbuf);
  12216. int i=1;
  12217. char filenametemp[50];
  12218. while(i < ftppathlen)
  12219. {
  12220. int len=ftppathlen-i;
  12221. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12222. {
  12223. DEBUG_INFO(" compare '/' all right\n");
  12224. break;
  12225. }
  12226. i=i+1;
  12227. }
  12228. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12229. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12230. filenametemp[i+1] = 0;
  12231. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12232. pch=strchr(temp,'@');
  12233. if(pch==NULL)
  12234. {
  12235. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12236. protocol, host, &port, path);
  12237. strcpy(user,"anonymous");
  12238. strcpy(password,"");
  12239. }
  12240. else
  12241. {
  12242. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12243. protocol, user, password, host, &port, path);
  12244. }
  12245. sscanf(host,"%[^/]%s",host1, path1);
  12246. sprintf(ftppath,"%s", path1);
  12247. //DEBUG_INFO("protocol =%s\n",protocol);
  12248. //DEBUG_INFO("user =%s\n",user);
  12249. //DEBUG_INFO("password =%s\n",password);
  12250. //DEBUG_INFO("host1 =%s\n",host1);
  12251. //DEBUG_INFO("port =%d\n",port);
  12252. //DEBUG_INFO("path1 =%s\n",path1);
  12253. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12254. //ftpFile(host, user, password, port, ftppath, fname);
  12255. //download firmware pthred
  12256. if(port == 0)
  12257. {
  12258. port = 21;
  12259. }
  12260. do
  12261. {
  12262. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12263. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12264. sleep(1);
  12265. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12266. if(!isSuccess)
  12267. {
  12268. //BulldogUtil.sleepMs(interval*1000);
  12269. DEBUG_INFO("Update firmware request and download file fail.\n");
  12270. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12271. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12272. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12273. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12274. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12275. }
  12276. else
  12277. {
  12278. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12279. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12280. }
  12281. retriesInt--;
  12282. }while((!isSuccess)&&(retriesInt >= 0));
  12283. }
  12284. else
  12285. {
  12286. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12287. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12288. sleep(1);
  12289. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12290. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12291. }
  12292. // OCPPPH only, must announce CSU upgrade firmware
  12293. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12294. interLock.isUpdateFirmwareGoing = 0;
  12295. pthread_exit(NULL);
  12296. }
  12297. int handleCertificateSignedRequest(char *uuid, char *payload)
  12298. {
  12299. mtrace();
  12300. int result = PASS;
  12301. json_object *CertificateSigned;
  12302. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12303. CertificateSigned = json_tokener_parse(payload);
  12304. if(!is_error(CertificateSigned))
  12305. {
  12306. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12307. }
  12308. json_object_put(CertificateSigned);
  12309. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12310. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12311. fclose(fp);
  12312. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12313. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12314. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12315. sendCertificateSignedConfirmation(uuid);
  12316. return result;
  12317. }
  12318. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12319. {
  12320. mtrace();
  12321. int result = PASS;
  12322. json_object *DeleteCertificate;
  12323. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12324. DeleteCertificate = json_tokener_parse(payload);
  12325. if(!is_error(DeleteCertificate))
  12326. {
  12327. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12328. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12329. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12330. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12331. }
  12332. json_object_put(DeleteCertificate);
  12333. /*
  12334. * TODO: Delete certificateSigned process
  12335. */
  12336. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12337. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12338. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12339. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12340. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12341. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12342. sendDeleteCertificateConfirmation(uuid);
  12343. return result;
  12344. }
  12345. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12346. {
  12347. mtrace();
  12348. int result = PASS;
  12349. json_object *ExtendedTriggerMessage;
  12350. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12351. ExtendedTriggerMessage = json_tokener_parse(payload);
  12352. if(!is_error(ExtendedTriggerMessage))
  12353. {
  12354. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12355. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12356. {
  12357. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12358. }
  12359. else
  12360. {
  12361. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12362. }
  12363. }
  12364. json_object_put(ExtendedTriggerMessage);
  12365. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12366. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12367. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12368. {
  12369. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12370. }
  12371. else
  12372. {
  12373. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12374. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12375. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12376. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12377. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12378. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12379. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12380. {
  12381. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12382. }
  12383. else
  12384. {
  12385. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12386. }
  12387. }
  12388. sendExtendedTriggerMessageConfirmation(uuid);
  12389. //==========================
  12390. // Trigger message
  12391. //==========================
  12392. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12393. {
  12394. //sendBootNotificationRequest();
  12395. server_sign = FALSE;
  12396. }
  12397. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12398. {
  12399. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12400. }
  12401. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12402. {
  12403. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12404. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12405. {
  12406. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12407. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12408. }
  12409. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12410. }
  12411. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12412. {
  12413. refreshStartTimer(&clientTime.Heartbeat);
  12414. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12415. }
  12416. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12417. {
  12418. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12419. {
  12420. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12421. }
  12422. else
  12423. {
  12424. for(int idx=0;idx< gunTotalNumber;idx++)
  12425. {
  12426. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12427. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12428. }
  12429. }
  12430. }
  12431. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12432. {
  12433. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12434. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12435. {
  12436. 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\" &");
  12437. }
  12438. }
  12439. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12440. {
  12441. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12442. {
  12443. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12444. }
  12445. else
  12446. {
  12447. for(int idx=0;idx< gunTotalNumber;idx++)
  12448. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12449. }
  12450. }
  12451. return result;
  12452. }
  12453. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12454. {
  12455. mtrace();
  12456. int result = PASS;
  12457. json_object *GetInstalledCertificateIds;
  12458. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12459. GetInstalledCertificateIds = json_tokener_parse(payload);
  12460. if(!is_error(GetInstalledCertificateIds))
  12461. {
  12462. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12463. }
  12464. json_object_put(GetInstalledCertificateIds);
  12465. /*
  12466. * TODO: Return installed certificate process
  12467. */
  12468. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12469. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12470. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12471. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12472. sendGetInstalledCertificateIdsConfirmation(uuid);
  12473. return result;
  12474. }
  12475. int handleGetLogRequest(char *uuid, char *payload)
  12476. {
  12477. mtrace();
  12478. int result = PASS;
  12479. json_object *GetLog;
  12480. DEBUG_INFO("handleGetLogRequest...\n");
  12481. GetLog = json_tokener_parse(payload);
  12482. if(!is_error(GetLog))
  12483. {
  12484. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12485. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12486. if(json_object_object_get(GetLog, "retries") != NULL)
  12487. {
  12488. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12489. }
  12490. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12491. {
  12492. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12493. }
  12494. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12495. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12496. {
  12497. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12498. }
  12499. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12500. {
  12501. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12502. }
  12503. }
  12504. json_object_put(GetLog);
  12505. /*
  12506. * TODO: Upload log process
  12507. */
  12508. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12509. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12510. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12511. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12512. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12513. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12514. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12515. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12516. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12517. sendGetLogConfirmation(uuid);
  12518. return result;
  12519. }
  12520. int handleInstallCertificateRequest(char *uuid, char *payload)
  12521. {
  12522. mtrace();
  12523. int result = PASS;
  12524. json_object *InstallCertificate;
  12525. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12526. InstallCertificate = json_tokener_parse(payload);
  12527. if(!is_error(InstallCertificate))
  12528. {
  12529. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12530. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12531. /*
  12532. * TODO: Install certificate process
  12533. */
  12534. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12535. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12536. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12537. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12538. sendInstallCertificateConfirmation(uuid);
  12539. }
  12540. json_object_put(InstallCertificate);
  12541. return result;
  12542. }
  12543. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12544. {
  12545. mtrace();
  12546. int result = PASS;
  12547. json_object *SignedUpdateFirmware;
  12548. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12549. SignedUpdateFirmware = json_tokener_parse(payload);
  12550. if(!is_error(SignedUpdateFirmware))
  12551. {
  12552. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12553. {
  12554. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12555. }
  12556. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12557. {
  12558. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12559. }
  12560. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12561. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12562. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12563. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12564. {
  12565. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12566. }
  12567. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12568. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12569. }
  12570. json_object_put(SignedUpdateFirmware);
  12571. /*
  12572. * TODO: Upgrade firmware process
  12573. */
  12574. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12575. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12576. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12577. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12578. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12579. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12580. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12581. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12582. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12583. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12584. sendInstallCertificateConfirmation(uuid);
  12585. return result;
  12586. }
  12587. int handleUnknownRequest(char *uuid, char *payload)
  12588. {
  12589. mtrace();
  12590. int result = PASS;
  12591. DEBUG_INFO("handleUnknownRequest...\n");
  12592. sendUnknownConfirmation(uuid);
  12593. result = PASS;
  12594. return result;
  12595. }
  12596. //==========================================
  12597. // Handle server response routine
  12598. //==========================================
  12599. void handleAuthorizeResponse(char *payload, int gun_index)
  12600. {
  12601. mtrace();
  12602. char expiryDatestr[30]={0};
  12603. char parentIdTagstr[20]={0};
  12604. char statusstr[20]={0};
  12605. int expiryDateISNULL=FALSE;
  12606. int parentIdTagISNULL=FALSE;
  12607. DEBUG_INFO("handleAuthorizeResponse...\n");
  12608. json_object *Authorize;
  12609. Authorize = json_tokener_parse(payload);
  12610. if(!is_error(Authorize))
  12611. {
  12612. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12613. {
  12614. // Required data
  12615. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12616. // Optional data
  12617. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12618. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12619. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12620. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12621. }
  12622. }
  12623. json_object_put(Authorize);
  12624. if(expiryDateISNULL == FALSE)
  12625. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12626. if(parentIdTagISNULL == FALSE)
  12627. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12628. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12629. //Update idTag information to authorization cache if supproted
  12630. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12631. {
  12632. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12633. }
  12634. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12635. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12636. authorizeRetryTimes = 0;
  12637. }
  12638. void handleBootNotificationResponse(char *payload, int gun_index)
  12639. {
  12640. mtrace();
  12641. char statusStr[12]={0};
  12642. char currentTimeStr[30]={0};
  12643. int intervalInt = 0;
  12644. DEBUG_INFO("handleBootNotificationResponse...\n");
  12645. json_object *BootNotification;
  12646. BootNotification = json_tokener_parse(payload);
  12647. if(!is_error(BootNotification))
  12648. {
  12649. // Required data
  12650. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12651. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12652. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12653. }
  12654. json_object_put(BootNotification);
  12655. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12656. BootNotificationInterval = intervalInt;
  12657. HeartBeatWaitTime = intervalInt;
  12658. //write back to ShmOCPP16DataPH->BootNotification
  12659. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12660. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12661. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12662. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12663. {
  12664. if((intervalInt == 0) || (intervalInt >= 10))
  12665. {
  12666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12667. HeartBeatWaitTime = intervalInt;
  12668. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12669. }
  12670. server_sign = TRUE;
  12671. server_pending =FALSE;
  12672. }
  12673. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12674. {
  12675. server_pending = TRUE;
  12676. }
  12677. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12678. srand(time(NULL));
  12679. refreshStartTimer(&clientTime.Heartbeat);
  12680. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12681. SetOcppConnStatus(TRUE);
  12682. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12683. }
  12684. void handleDataTransferResponse(char *payload, int gun_index)
  12685. {
  12686. char sstr[160]={0};//sstr[200]={ 0 };
  12687. int c = 0;
  12688. char *loc;
  12689. DEBUG_INFO("handleDataTransferResponse ...\n");
  12690. loc = strstr(payload, "status");
  12691. c = 0;
  12692. while (loc[3+strlen("status")+c] != '\"')
  12693. {
  12694. sstr[c] = loc[3+strlen("status")+c];
  12695. c++;
  12696. }
  12697. sstr[c] = '\0';
  12698. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12699. }
  12700. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12701. {
  12702. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12703. //struct json_object *obj;
  12704. // obj = json_tokener_parse(payload);
  12705. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12706. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12707. //No fields are defined.
  12708. }
  12709. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12710. {
  12711. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12712. //struct json_object *obj;
  12713. // obj = json_tokener_parse(payload);
  12714. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12715. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12716. //No fields are defined.
  12717. }
  12718. void handleHeartbeatResponse(char *payload, int gun_index)
  12719. {
  12720. mtrace();
  12721. DEBUG_INFO("handleHeartbeatResponse...\n");
  12722. json_object *Heartbeat;
  12723. Heartbeat = json_tokener_parse(payload);
  12724. if(!is_error(Heartbeat))
  12725. {
  12726. // Required data
  12727. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12728. }
  12729. json_object_put(Heartbeat);
  12730. if(FirstHeartBeat == 0)
  12731. {
  12732. FirstHeartBeat = 1;
  12733. DEBUG_INFO("FirstHeartBeat \n");
  12734. }
  12735. HeartBeatWithNOResponse = 0;
  12736. refreshStartTimer(&clientTime.Heartbeat);
  12737. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12738. }
  12739. void handleMeterValuesResponse(char *payload, int gun_index)
  12740. {
  12741. mtrace();
  12742. DEBUG_INFO("handleMeterValuesResponse...\n");
  12743. isQueueSendable = 1;
  12744. }
  12745. void handleStartTransactionResponse(char *payload, int gun_index)
  12746. {
  12747. mtrace();
  12748. //int transactionIdInt = 0;
  12749. FILE *outfile;
  12750. char data[100]={0};
  12751. DEBUG_INFO("handleStartTransactionResponse...\n");
  12752. json_object *StartTransaction;
  12753. StartTransaction = json_tokener_parse(payload);
  12754. if(!is_error(StartTransaction))
  12755. {
  12756. // Required data
  12757. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12758. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12759. // Optional data
  12760. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12761. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12762. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12763. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12764. }
  12765. json_object_put(StartTransaction);
  12766. isQueueSendable = 1;
  12767. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12768. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12769. //-----------Start : write to the Queue TransactionId file -----------------//
  12770. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12771. {}
  12772. else
  12773. {
  12774. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12775. if(log == NULL)
  12776. {
  12777. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12778. return ;
  12779. }
  12780. else
  12781. {
  12782. fclose(log);
  12783. }
  12784. }
  12785. // open file for writing
  12786. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12787. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12788. {
  12789. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12790. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12791. fputs(data, outfile);
  12792. fclose (outfile);
  12793. }
  12794. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12795. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12796. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12797. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12798. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12799. }
  12800. void handleStatusNotificationResponse(char *payload, int gun_index)
  12801. {
  12802. mtrace();
  12803. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12804. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12805. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12806. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12807. }
  12808. void handleStopTransactionnResponse(char *payload, int gun_index)
  12809. {
  12810. mtrace();
  12811. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12812. json_object *StopTransaction;
  12813. StopTransaction = json_tokener_parse(payload);
  12814. if(!is_error(StopTransaction))
  12815. {
  12816. // Optional data
  12817. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12818. {
  12819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12820. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12821. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12822. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12824. }
  12825. }
  12826. json_object_put(StopTransaction);
  12827. isQueueSendable = 1;
  12828. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12829. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12830. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12831. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12832. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12833. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12834. }
  12835. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12836. {
  12837. mtrace();
  12838. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12839. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12840. }
  12841. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12842. {
  12843. mtrace();
  12844. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12845. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12846. }
  12847. void handleSignCertificateResponse(char *payload, int gun_index)
  12848. {
  12849. mtrace();
  12850. DEBUG_INFO("handleSignCertificateResponse...\n");
  12851. json_object *SignCertificate;
  12852. SignCertificate = json_tokener_parse(payload);
  12853. if(!is_error(SignCertificate))
  12854. {
  12855. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12856. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12857. }
  12858. json_object_put(SignCertificate);
  12859. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12860. }
  12861. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12862. {
  12863. mtrace();
  12864. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12865. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12866. }
  12867. //==========================================
  12868. // Handle Error routine
  12869. //==========================================
  12870. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12871. {
  12872. mtrace();
  12873. #ifdef SystemLogMessage
  12874. DEBUG_INFO("errorCode: %s\n", errorCode);
  12875. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12876. DEBUG_INFO("errorDetails: %s\n", payload);
  12877. #endif
  12878. }
  12879. //===============================================
  12880. // Common routine
  12881. //===============================================
  12882. int initialConfigurationTable(void)
  12883. {
  12884. //clock_t start_t, end_t, total_t;
  12885. FILE *fp;
  12886. FILE *outfile;
  12887. char str[512]={0};
  12888. char sstr[256]={0};
  12889. int c = 0;
  12890. char *loc;
  12891. int confVersion = 11;
  12892. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12893. //start_t = clock();
  12894. //printf("Starting of the program, start_t = %ld\n", start_t);
  12895. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12896. // Check configuration file size is correct
  12897. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12898. {
  12899. struct stat st;
  12900. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12901. if(st.st_size < 3100)
  12902. {
  12903. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12904. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12905. }
  12906. }
  12907. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12908. {
  12909. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12910. if(outfile == NULL)
  12911. {
  12912. DEBUG_INFO("Error opening file\n");
  12913. return FALSE;
  12914. }
  12915. /*Core Profile*/
  12916. //AllowOfflineTxForUnknownId
  12917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12921. //AuthorizationCacheEnabled
  12922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12926. //AuthorizeRemoteTxRequests
  12927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12931. //BlinkRepeat
  12932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12936. //ClockAlignedDataInterval
  12937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12941. //ConnectionTimeOut
  12942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12946. //GetConfigurationMaxKeys
  12947. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12951. // HeartbeatInterval
  12952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12956. // LightIntensity
  12957. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12961. // LocalAuthorizeOffline
  12962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12966. // LocalPreAuthorize
  12967. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12971. // MaxEnergyOnInvalidId
  12972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12976. // MeterValuesAlignedData
  12977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12980. 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" );
  12981. else
  12982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12984. // MeterValuesAlignedDataMaxLength
  12985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12989. else
  12990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12992. // MeterValuesSampledData
  12993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12996. 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" );
  12997. else
  12998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13000. // MeterValuesSampledDataMaxLength
  13001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13005. else
  13006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13008. // MeterValueSampleInterval
  13009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13013. // MinimumStatusDuration
  13014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13017. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13019. // NumberOfConnectors
  13020. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13023. {
  13024. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13025. }
  13026. else
  13027. {
  13028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13029. }
  13030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13031. // ResetRetries
  13032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13036. // ConnectorPhaseRotation
  13037. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13041. // ConnectorPhaseRotationMaxLength
  13042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13046. // StopTransactionOnEVSideDisconnect
  13047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13051. // StopTransactionOnInvalidId
  13052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13056. // StopTxnAlignedData
  13057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13061. // StopTxnAlignedDataMaxLength
  13062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13066. // StopTxnSampledData
  13067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13071. else
  13072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13074. // StopTxnSampledDataMaxLength
  13075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13078. {
  13079. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13080. }
  13081. else
  13082. {
  13083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13084. }
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13086. // SupportedFeatureProfiles
  13087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13091. // SupportedFeatureProfilesMaxLength
  13092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13096. // TransactionMessageAttempts
  13097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13100. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13102. // TransactionMessageRetryInterval
  13103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13106. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13108. // UnlockConnectorOnEVSideDisconnect
  13109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13113. // WebSocketPingInterval
  13114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13118. // QueueOffLineMeterValues
  13119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13123. // AuthorizationKey
  13124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13128. // SecurityProfile
  13129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13133. // DefaultPrice
  13134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13138. // CustomDisplayCostAndPrice
  13139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13143. // CustomIdleFeeAfterStop
  13144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13148. // SystemUptimeSec
  13149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13153. // FreeVend
  13154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13158. // OcppServer
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13161. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13163. // MaintainServer
  13164. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13166. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13168. // Configuration Version
  13169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13171. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13173. //* Local Auth List Management Profile*/
  13174. #if 0
  13175. //For OCTT Test Case
  13176. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13179. #endif
  13180. #if 1
  13181. //LocalAuthListEnabled
  13182. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13186. #endif
  13187. //LocalAuthListMaxLength
  13188. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13192. //SendLocalListMaxLength
  13193. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13197. //ReserveConnectorZeroSupported
  13198. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13202. //* Smart Charging Profile */
  13203. //ChargeProfileMaxStackLevel
  13204. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13208. // ChargingScheduleAllowedChargingRateUnit
  13209. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13213. // ChargingScheduleMaxPeriods
  13214. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13218. // ConnectorSwitch3to1PhaseSupported
  13219. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13223. // MaxChargingProfilesInstalled
  13224. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13228. fclose(outfile);
  13229. }
  13230. else
  13231. {
  13232. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13233. char keystr[60]={0};
  13234. char readonlystr[10]={0};
  13235. char valuestr[256]={0};
  13236. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13237. if(fp == NULL) {
  13238. DEBUG_INFO("Error opening file");
  13239. return FALSE;
  13240. }
  13241. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13242. {
  13243. //DEBUG_INFO("Get Configuration \n");
  13244. if(strlen(str) > 0)
  13245. {
  13246. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13247. //*************************key*********************************/
  13248. if(strstr(str, "key") != NULL)
  13249. {
  13250. loc = strstr(str, "key");
  13251. c = 0;
  13252. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13253. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13254. {
  13255. sstr[c] = loc[strlen("key")+3+c];
  13256. c++;
  13257. }
  13258. sstr[c] = '\0';
  13259. strcpy(keystr,sstr);
  13260. }
  13261. //*************************readonly*********************************/
  13262. if(strstr(str, "readonly") != NULL)
  13263. {
  13264. loc = strstr(str, "readonly");
  13265. c = 0;
  13266. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13267. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13268. {
  13269. sstr[c] = loc[strlen("readonly")+2+c];
  13270. c++;
  13271. }
  13272. sstr[c] = '\0';
  13273. strcpy(readonlystr,sstr);
  13274. }
  13275. //*************************value*********************************/
  13276. if(strstr(str, "value") != NULL)
  13277. {
  13278. loc = strstr(str, "value");
  13279. c = 0;
  13280. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13281. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13282. {
  13283. sstr[c] = loc[strlen("value")+3+c];
  13284. c++;
  13285. }
  13286. sstr[c] = '\0';
  13287. strcpy(valuestr,sstr);
  13288. }
  13289. // DEBUG_INFO("keystr=%s\n",keystr);
  13290. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13291. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13292. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13293. {
  13294. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13296. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13297. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13298. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13299. }
  13300. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13301. {
  13302. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13305. }
  13306. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13307. {
  13308. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13310. }
  13311. if(strcmp(keystr, "BlinkRepeat") == 0)
  13312. {
  13313. //Charger.BlinkRepeat = Integer.parseInt(value);
  13314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13316. }
  13317. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13318. {
  13319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13321. }
  13322. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13323. {
  13324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13326. }
  13327. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13328. {
  13329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13330. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13331. }
  13332. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13333. {
  13334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13335. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13336. HeartBeatWaitTime = atoi(valuestr);
  13337. }
  13338. if(strcmp(keystr, "LightIntensity") == 0)
  13339. {
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13342. }
  13343. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13344. {
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13347. }
  13348. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13349. {
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13352. }
  13353. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13354. {
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13357. }
  13358. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13359. {
  13360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13362. }
  13363. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13364. {
  13365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13367. }
  13368. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13369. {
  13370. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13372. }
  13373. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13374. {
  13375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13377. }
  13378. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13379. {
  13380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13382. }
  13383. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13384. {
  13385. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13387. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13388. }
  13389. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13390. {
  13391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13393. }
  13394. if(strcmp(keystr, "ResetRetries") == 0)
  13395. {
  13396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13398. }
  13399. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13400. {
  13401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13403. }
  13404. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13405. {
  13406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13408. }
  13409. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13410. {
  13411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13413. }
  13414. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13415. {
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13418. }
  13419. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13420. {
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13423. }
  13424. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13425. {
  13426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13428. }
  13429. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13430. {
  13431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13433. }
  13434. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13435. {
  13436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13438. }
  13439. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13440. {
  13441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13442. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13443. }
  13444. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13445. {
  13446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13447. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13448. }
  13449. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13450. {
  13451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13453. TransactionMessageAttemptsValue = atoi(valuestr);
  13454. }
  13455. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13456. {
  13457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13459. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13460. }
  13461. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13462. {
  13463. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13465. }
  13466. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13467. {
  13468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13470. }
  13471. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13472. {
  13473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13475. }
  13476. if(strcmp(keystr, "AuthorizationKey") == 0)
  13477. {
  13478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13479. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13481. }
  13482. if(strcmp(keystr, "SecurityProfile") == 0)
  13483. {
  13484. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13485. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13486. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13487. }
  13488. if(strcmp(keystr, "DefaultPrice") == 0)
  13489. {
  13490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13492. }
  13493. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13494. {
  13495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13497. }
  13498. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13499. {
  13500. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13502. }
  13503. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13504. {
  13505. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13507. }
  13508. if(strcmp(keystr, "FreeVend") == 0)
  13509. {
  13510. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13512. }
  13513. if(strcmp(keystr, "OcppServer") == 0)
  13514. {
  13515. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13516. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13517. }
  13518. if(strcmp(keystr, "MaintainServer") == 0)
  13519. {
  13520. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13521. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13522. }
  13523. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13524. {
  13525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13527. }
  13528. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13529. {
  13530. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13532. }
  13533. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13534. {
  13535. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13537. }
  13538. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13539. {
  13540. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13542. }
  13543. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13544. {
  13545. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13547. }
  13548. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13549. {
  13550. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13552. }
  13553. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13554. {
  13555. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13557. }
  13558. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13559. {
  13560. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13562. }
  13563. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13564. {
  13565. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13567. }
  13568. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13569. {
  13570. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13572. }
  13573. }
  13574. }
  13575. fclose(fp);
  13576. }
  13577. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13578. {
  13579. return PASS;
  13580. }
  13581. else
  13582. {
  13583. return FAIL;
  13584. }
  13585. }
  13586. void StoreConfigurationTable(void)
  13587. {
  13588. FILE *outfile;
  13589. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13590. if(outfile == NULL)
  13591. {
  13592. DEBUG_INFO("Error opening file");
  13593. return ;
  13594. }
  13595. /*Core Profile*/
  13596. //AllowOfflineTxForUnknownId
  13597. /*
  13598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13599. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13600. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13602. */
  13603. //DEBUG_INFO("data=%s\n",data);
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13605. //AuthorizationCacheEnabled
  13606. /*
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13610. */
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13612. //AuthorizeRemoteTxRequests
  13613. /*
  13614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13617. */
  13618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13619. //BlinkRepeat
  13620. /*
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13624. */
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13626. //ClockAlignedDataInterval
  13627. /*
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13631. */
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13633. //ConnectionTimeOut
  13634. /*
  13635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13638. */
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13640. //GetConfigurationMaxKeys
  13641. /*
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13645. */
  13646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13647. // HeartbeatInterval
  13648. /*
  13649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13652. */
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13654. // LightIntensity
  13655. /*
  13656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13659. */
  13660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13661. // LocalAuthorizeOffline
  13662. /*
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13666. */
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13668. // LocalPreAuthorize
  13669. /*
  13670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13673. */
  13674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13675. // MaxEnergyOnInvalidId
  13676. /*
  13677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13680. */
  13681. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13683. // MeterValuesAlignedData
  13684. /*
  13685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13688. */
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13690. // MeterValuesAlignedDataMaxLength
  13691. /*
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13695. */
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13697. // MeterValuesSampledData
  13698. /*
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13702. */
  13703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13704. // MeterValuesSampledDataMaxLength
  13705. /*
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13709. */
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13711. // MeterValueSampleInterval
  13712. /*
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13716. */
  13717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13718. // MinimumStatusDuration
  13719. /*
  13720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13723. */
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13725. // NumberOfConnectors
  13726. /*
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13730. {
  13731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13732. }
  13733. else
  13734. {
  13735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13736. }
  13737. */
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13739. // ResetRetries
  13740. /*
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13744. */
  13745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13746. // ConnectorPhaseRotation
  13747. /*
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13751. */
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13753. // ConnectorPhaseRotationMaxLength
  13754. /*
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13758. */
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13760. // StopTransactionOnEVSideDisconnect
  13761. /*
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13765. */
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13767. // StopTransactionOnInvalidId
  13768. /*
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13772. */
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13774. // StopTxnAlignedData
  13775. /*
  13776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13779. */
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13781. // StopTxnAlignedDataMaxLength
  13782. /*
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13786. */
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13788. // StopTxnSampledData
  13789. /*
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13793. */
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13795. // StopTxnSampledDataMaxLength
  13796. /*
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13800. */
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13802. // SupportedFeatureProfiles
  13803. /*
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13807. */
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13809. // SupportedFeatureProfilesMaxLength
  13810. /*
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13814. */
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13816. // TransactionMessageAttempts
  13817. /*
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13821. */
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13823. // TransactionMessageRetryInterval
  13824. /*
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13828. */
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13830. // UnlockConnectorOnEVSideDisconnect
  13831. /*
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13835. */
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13837. // WebSocketPingInterval
  13838. /*
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13842. */
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13844. // QueueOffLineMeterValues
  13845. /*
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13849. */
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13851. // AuthorizationKey
  13852. /*
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13856. */
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13858. // SecurityProfile
  13859. /*
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13863. */
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13865. // DefaultPrice
  13866. /*
  13867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13870. */
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13872. // CustomDisplayCostAndPrice
  13873. /*
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13877. */
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13879. // CustomIdleFeeAfterStop
  13880. /*
  13881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13884. */
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13886. // SystemUptimeSec
  13887. /*
  13888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13891. */
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13893. // FreeVend
  13894. /*
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13898. */
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13900. // OcppServer
  13901. /*
  13902. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  13905. */
  13906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13907. // MaintainServer
  13908. /*
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  13912. */
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13914. // ConfigurationVersion
  13915. /*
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13919. */
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13921. //* Local Auth List Management Profile*/
  13922. //LocalAuthListEnabled
  13923. /*
  13924. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13927. */
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13929. //LocalAuthListMaxLength
  13930. /*
  13931. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13934. */
  13935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13936. //SendLocalListMaxLength
  13937. /*
  13938. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13941. */
  13942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13943. //ReserveConnectorZeroSupported
  13944. /*
  13945. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13948. */
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13950. //* Smart Charging Profile */
  13951. //ChargeProfileMaxStackLevel
  13952. /*
  13953. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13956. */
  13957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13958. // ChargingScheduleAllowedChargingRateUnit
  13959. /*
  13960. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13963. */
  13964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13965. // ChargingScheduleMaxPeriods
  13966. /*
  13967. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13970. */
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13972. // ConnectorSwitch3to1PhaseSupported
  13973. /*
  13974. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13977. */
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13979. // MaxChargingProfilesInstalled
  13980. /*
  13981. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13984. */
  13985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13986. fclose(outfile);
  13987. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13988. }
  13989. void getKeyValue(char *keyReq)
  13990. {
  13991. int isEmpty = FALSE;
  13992. int isKnowKey = FALSE;
  13993. DEBUG_INFO("keyReq = %s\n", keyReq);
  13994. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13995. isEmpty = TRUE;
  13996. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13997. {
  13998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14001. {
  14002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14003. }
  14004. else
  14005. {
  14006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14007. }
  14008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14009. isKnowKey = TRUE;
  14010. }
  14011. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14012. {
  14013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14015. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14016. {
  14017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14018. }
  14019. else
  14020. {
  14021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14022. }
  14023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14024. isKnowKey = TRUE;
  14025. }
  14026. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14027. {
  14028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14030. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14031. {
  14032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14033. }
  14034. else
  14035. {
  14036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14037. }
  14038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14039. isKnowKey = TRUE;
  14040. }
  14041. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14042. {
  14043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14045. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14046. {
  14047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14048. }
  14049. else
  14050. {
  14051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14052. }
  14053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14054. isKnowKey = TRUE;
  14055. }
  14056. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14057. {
  14058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14060. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14061. {
  14062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14063. }
  14064. else
  14065. {
  14066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14067. }
  14068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14069. isKnowKey = TRUE;
  14070. }
  14071. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14072. {
  14073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14075. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14076. {
  14077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14078. }
  14079. else
  14080. {
  14081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14082. }
  14083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14084. isKnowKey = TRUE;
  14085. }
  14086. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14087. {
  14088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14090. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14091. {
  14092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14093. }
  14094. else
  14095. {
  14096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14097. }
  14098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14099. isKnowKey = TRUE;
  14100. }
  14101. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14102. {
  14103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14105. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14106. {
  14107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14108. }
  14109. else
  14110. {
  14111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14112. }
  14113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14114. isKnowKey = TRUE;
  14115. }
  14116. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14117. {
  14118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14120. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14121. {
  14122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14123. }
  14124. else
  14125. {
  14126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14127. }
  14128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14129. isKnowKey = TRUE;
  14130. }
  14131. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14132. {
  14133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14135. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14136. {
  14137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14138. }
  14139. else
  14140. {
  14141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14142. }
  14143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14144. isKnowKey = TRUE;
  14145. }
  14146. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14147. {
  14148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14150. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14151. {
  14152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14153. }
  14154. else
  14155. {
  14156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14157. }
  14158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14159. isKnowKey = TRUE;
  14160. }
  14161. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14162. {
  14163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14165. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14166. {
  14167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14168. }
  14169. else
  14170. {
  14171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14172. }
  14173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14174. isKnowKey = TRUE;
  14175. }
  14176. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14177. {
  14178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14181. {
  14182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14183. }
  14184. else
  14185. {
  14186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14187. }
  14188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14189. isKnowKey = TRUE;
  14190. }
  14191. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14192. {
  14193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14195. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14196. {
  14197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14198. }
  14199. else
  14200. {
  14201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14202. }
  14203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14204. isKnowKey = TRUE;
  14205. }
  14206. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14207. {
  14208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14210. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14211. {
  14212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14213. }
  14214. else
  14215. {
  14216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14217. }
  14218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14219. isKnowKey = TRUE;
  14220. }
  14221. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14222. {
  14223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14225. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14226. {
  14227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14228. }
  14229. else
  14230. {
  14231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14232. }
  14233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14234. isKnowKey = TRUE;
  14235. }
  14236. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14237. {
  14238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14240. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14241. {
  14242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14243. }
  14244. else
  14245. {
  14246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14247. }
  14248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14249. isKnowKey = TRUE;
  14250. }
  14251. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14252. {
  14253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14255. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14256. {
  14257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14258. }
  14259. else
  14260. {
  14261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14262. }
  14263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14264. isKnowKey = TRUE;
  14265. }
  14266. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14267. {
  14268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14270. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14271. {
  14272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14273. }
  14274. else
  14275. {
  14276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14277. }
  14278. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14280. isKnowKey = TRUE;
  14281. }
  14282. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14283. {
  14284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14286. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14287. {
  14288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14289. }
  14290. else
  14291. {
  14292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14293. }
  14294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14295. isKnowKey = TRUE;
  14296. }
  14297. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14298. {
  14299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14301. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14302. {
  14303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14304. }
  14305. else
  14306. {
  14307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14308. }
  14309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14310. isKnowKey = TRUE;
  14311. }
  14312. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14313. {
  14314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14317. {
  14318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14319. }
  14320. else
  14321. {
  14322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14323. }
  14324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14325. isKnowKey = TRUE;
  14326. }
  14327. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14328. {
  14329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14331. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14332. {
  14333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14334. }
  14335. else
  14336. {
  14337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14338. }
  14339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14340. isKnowKey = TRUE;
  14341. }
  14342. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14343. {
  14344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14347. {
  14348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14349. }
  14350. else
  14351. {
  14352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14353. }
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14355. isKnowKey = TRUE;
  14356. }
  14357. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14358. {
  14359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14362. {
  14363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14364. }
  14365. else
  14366. {
  14367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14368. }
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14370. isKnowKey = TRUE;
  14371. }
  14372. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14373. {
  14374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14377. {
  14378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14379. }
  14380. else
  14381. {
  14382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14383. }
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14385. isKnowKey = TRUE;
  14386. }
  14387. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14388. {
  14389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14392. {
  14393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14394. }
  14395. else
  14396. {
  14397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14398. }
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14400. isKnowKey = TRUE;
  14401. }
  14402. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14403. {
  14404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14407. {
  14408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14409. }
  14410. else
  14411. {
  14412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14413. }
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14415. isKnowKey = TRUE;
  14416. }
  14417. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14418. {
  14419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14422. {
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14424. }
  14425. else
  14426. {
  14427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14428. }
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14430. isKnowKey = TRUE;
  14431. }
  14432. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14433. {
  14434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14437. {
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14439. }
  14440. else
  14441. {
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14443. }
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14445. isKnowKey = TRUE;
  14446. }
  14447. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14448. {
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14451. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14452. {
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14454. }
  14455. else
  14456. {
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14458. }
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14460. isKnowKey = TRUE;
  14461. }
  14462. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14463. {
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14466. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14467. {
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14469. }
  14470. else
  14471. {
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14473. }
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14475. isKnowKey = TRUE;
  14476. }
  14477. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14478. {
  14479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14482. {
  14483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14484. }
  14485. else
  14486. {
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14488. }
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14490. isKnowKey = TRUE;
  14491. }
  14492. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14493. {
  14494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14496. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14497. {
  14498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14499. }
  14500. else
  14501. {
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14503. }
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14505. isKnowKey = TRUE;
  14506. }
  14507. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14508. {
  14509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14512. {
  14513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14514. }
  14515. else
  14516. {
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14518. }
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14520. isKnowKey = TRUE;
  14521. }
  14522. /*
  14523. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14528. {
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14530. }
  14531. else
  14532. {
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14534. }
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14536. isKnowKey = TRUE;
  14537. }*/
  14538. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14543. {
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14545. }
  14546. else
  14547. {
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14549. }
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14551. isKnowKey = TRUE;
  14552. }
  14553. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14557. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14558. {
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14560. }
  14561. else
  14562. {
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14564. }
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14566. isKnowKey = TRUE;
  14567. }
  14568. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14573. {
  14574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14575. }
  14576. else
  14577. {
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14579. }
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14581. isKnowKey = TRUE;
  14582. }
  14583. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14587. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14588. {
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14590. }
  14591. else
  14592. {
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14594. }
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14596. isKnowKey = TRUE;
  14597. }
  14598. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14599. {
  14600. struct sysinfo s_info;
  14601. int error = sysinfo(&s_info);
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14605. {
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14607. }
  14608. else
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14611. }
  14612. if(error != 0)
  14613. {
  14614. DEBUG_WARN("System uptime get error: %d\n", error);
  14615. }
  14616. else
  14617. {
  14618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14619. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14620. }
  14621. isKnowKey = TRUE;
  14622. }
  14623. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14627. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14628. {
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14630. }
  14631. else
  14632. {
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14634. }
  14635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14636. isKnowKey = TRUE;
  14637. }
  14638. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14639. {
  14640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14643. {
  14644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14645. }
  14646. else
  14647. {
  14648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14649. }
  14650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14651. isKnowKey = TRUE;
  14652. }
  14653. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14654. {
  14655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14658. {
  14659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14660. }
  14661. else
  14662. {
  14663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14664. }
  14665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14666. isKnowKey = TRUE;
  14667. }
  14668. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14673. {
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14675. }
  14676. else
  14677. {
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14679. }
  14680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14681. isKnowKey = TRUE;
  14682. }
  14683. #if 1
  14684. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14685. {
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14688. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14689. {
  14690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14691. }
  14692. else
  14693. {
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14695. }
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14697. isKnowKey = TRUE;
  14698. }
  14699. #endif
  14700. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14704. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14707. }
  14708. else
  14709. {
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14711. }
  14712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14713. isKnowKey = TRUE;
  14714. }
  14715. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14719. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14722. }
  14723. else
  14724. {
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14726. }
  14727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14728. isKnowKey = TRUE;
  14729. }
  14730. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14734. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14737. }
  14738. else
  14739. {
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14741. }
  14742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14743. isKnowKey = TRUE;
  14744. }
  14745. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14749. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14752. }
  14753. else
  14754. {
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14756. }
  14757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14758. isKnowKey = TRUE;
  14759. }
  14760. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14761. {
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14764. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14767. }
  14768. else
  14769. {
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14771. }
  14772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14773. isKnowKey = TRUE;
  14774. }
  14775. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14779. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14782. }
  14783. else
  14784. {
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14786. }
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14788. isKnowKey = TRUE;
  14789. }
  14790. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14794. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14797. }
  14798. else
  14799. {
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14801. }
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14803. isKnowKey = TRUE;
  14804. }
  14805. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14809. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14812. }
  14813. else
  14814. {
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14816. }
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14818. isKnowKey = TRUE;
  14819. }
  14820. //=========================================================
  14821. if(!isEmpty && !isKnowKey)
  14822. {
  14823. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14824. strcpy(unknownkey[UnknownKeynum], keyReq);
  14825. UnknownKeynum = UnknownKeynum + 1;
  14826. }
  14827. }
  14828. void processUnkownKey(void)
  14829. {
  14830. DEBUG_INFO("processUnkownKey...\n");
  14831. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14832. for(int index=0; index < UnknownKeynum; index++)
  14833. {
  14834. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14835. {
  14836. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14837. }
  14838. }
  14839. }
  14840. int setKeyValue(char *key, char *value)
  14841. {
  14842. int isSuccess = NotSupported;
  14843. int check_ascii=0;
  14844. char str[501]={0};
  14845. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14846. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14847. {
  14848. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14849. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14850. {
  14851. strcpy(str, (const char*)value);
  14852. for(int i = 0; str[i]; i++){
  14853. str[i] = tolower(str[i]);
  14854. }
  14855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14856. isSuccess = ConfigurationStatus_Accepted;
  14857. }
  14858. else
  14859. {
  14860. isSuccess = ConfigurationStatus_Rejected;
  14861. }
  14862. }
  14863. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14864. {
  14865. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14866. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14867. {
  14868. strcpy(str, (const char*)value);
  14869. for(int i = 0; str[i]; i++){
  14870. str[i] = tolower(str[i]);
  14871. }
  14872. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14873. isSuccess = ConfigurationStatus_Accepted;
  14874. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14875. }
  14876. else
  14877. {
  14878. isSuccess = ConfigurationStatus_Rejected;
  14879. }
  14880. }
  14881. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14882. {
  14883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14884. {
  14885. strcpy(str, (const char*)value);
  14886. for(int i = 0; str[i]; i++)
  14887. {
  14888. str[i] = tolower(str[i]);
  14889. }
  14890. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14891. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14892. isSuccess = ConfigurationStatus_Accepted;
  14893. }
  14894. else
  14895. {
  14896. isSuccess = ConfigurationStatus_Rejected;
  14897. }
  14898. }
  14899. if(strcmp(key, "BlinkRepeat") == 0)
  14900. {
  14901. //Charger.BlinkRepeat = Integer.parseInt(value);
  14902. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14903. {
  14904. check_ascii = value[0];
  14905. if( (check_ascii < 48) || (check_ascii > 57) )
  14906. {
  14907. isSuccess = ConfigurationStatus_Rejected;
  14908. }
  14909. else
  14910. {
  14911. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14912. isSuccess = ConfigurationStatus_Accepted;
  14913. }
  14914. }
  14915. else
  14916. {
  14917. isSuccess = ConfigurationStatus_Rejected;
  14918. }
  14919. }
  14920. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14921. {
  14922. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14923. {
  14924. check_ascii = value[0];
  14925. if( (check_ascii < 48) || (check_ascii > 57) )
  14926. {
  14927. isSuccess = ConfigurationStatus_Rejected;
  14928. }
  14929. else
  14930. {
  14931. if((atoi(value) == 0) || (atoi(value) >= 5))
  14932. {
  14933. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14934. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14935. isSuccess = ConfigurationStatus_Accepted;
  14936. }
  14937. else
  14938. isSuccess = ConfigurationStatus_Rejected;
  14939. }
  14940. }
  14941. else
  14942. {
  14943. isSuccess = ConfigurationStatus_Rejected;
  14944. }
  14945. }
  14946. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14947. {
  14948. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14949. {
  14950. check_ascii = value[0];
  14951. if( (check_ascii < 48) || (check_ascii > 57) )
  14952. {
  14953. isSuccess = ConfigurationStatus_Rejected;
  14954. }
  14955. else
  14956. {
  14957. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14959. isSuccess = ConfigurationStatus_Accepted;
  14960. }
  14961. }
  14962. else
  14963. {
  14964. isSuccess = ConfigurationStatus_Rejected;
  14965. }
  14966. }
  14967. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14968. {
  14969. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14970. {
  14971. check_ascii = value[0];
  14972. if( (check_ascii < 48) || (check_ascii > 57) )
  14973. {
  14974. isSuccess = ConfigurationStatus_Rejected;
  14975. }
  14976. else
  14977. {
  14978. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14980. isSuccess = ConfigurationStatus_Accepted;
  14981. }
  14982. }
  14983. else
  14984. {
  14985. isSuccess = ConfigurationStatus_Rejected;
  14986. }
  14987. }
  14988. if(strcmp(key, "HeartbeatInterval") == 0)
  14989. {
  14990. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14991. {
  14992. check_ascii = value[0];
  14993. if( (check_ascii < 48) || (check_ascii > 57) )
  14994. {
  14995. isSuccess = ConfigurationStatus_Rejected;
  14996. }
  14997. else
  14998. {
  14999. if((atoi(value) == 0) || (atoi(value) >= 10))
  15000. {
  15001. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15002. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15003. HeartBeatWaitTime = atoi(value);
  15004. isSuccess = ConfigurationStatus_Accepted;
  15005. }
  15006. else
  15007. {
  15008. isSuccess = ConfigurationStatus_Rejected;
  15009. }
  15010. }
  15011. }
  15012. else
  15013. {
  15014. isSuccess = ConfigurationStatus_Rejected;
  15015. }
  15016. }
  15017. if(strcmp(key, "LightIntensity") == 0)
  15018. {
  15019. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15020. {
  15021. check_ascii = value[0];
  15022. if( (check_ascii < 48) || (check_ascii > 57) )
  15023. {
  15024. isSuccess = ConfigurationStatus_Rejected;
  15025. }
  15026. else
  15027. {
  15028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15029. isSuccess = ConfigurationStatus_Accepted;
  15030. }
  15031. }
  15032. else
  15033. {
  15034. isSuccess = ConfigurationStatus_Rejected;
  15035. }
  15036. }
  15037. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15038. {
  15039. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15040. {
  15041. strcpy(str, (const char*)value);
  15042. for(int i = 0; str[i]; i++)
  15043. {
  15044. str[i] = tolower(str[i]);
  15045. }
  15046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15047. isSuccess = ConfigurationStatus_Accepted;
  15048. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15049. }
  15050. else
  15051. {
  15052. isSuccess = ConfigurationStatus_Rejected;
  15053. }
  15054. }
  15055. if(strcmp(key, "LocalPreAuthorize") == 0)
  15056. {
  15057. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15058. {
  15059. strcpy(str, (const char*)value);
  15060. for(int i = 0; str[i]; i++)
  15061. {
  15062. str[i] = tolower(str[i]);
  15063. }
  15064. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15065. isSuccess = ConfigurationStatus_Accepted;
  15066. }
  15067. else
  15068. {
  15069. isSuccess = ConfigurationStatus_Rejected;
  15070. }
  15071. }
  15072. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15073. {
  15074. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15075. {
  15076. check_ascii = value[0];
  15077. if( (check_ascii < 48) || (check_ascii > 57) )
  15078. {
  15079. isSuccess = ConfigurationStatus_Rejected;
  15080. }
  15081. else
  15082. {
  15083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15084. isSuccess = ConfigurationStatus_Accepted;
  15085. }
  15086. }
  15087. else
  15088. {
  15089. isSuccess = ConfigurationStatus_Rejected;
  15090. }
  15091. }
  15092. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15093. {
  15094. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15095. {
  15096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15097. isSuccess = ConfigurationStatus_Accepted;
  15098. }
  15099. else
  15100. {
  15101. isSuccess = ConfigurationStatus_Rejected;
  15102. }
  15103. }
  15104. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15105. {
  15106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15107. {
  15108. check_ascii = value[0];
  15109. if( (check_ascii < 48) || (check_ascii > 57) )
  15110. {
  15111. isSuccess = ConfigurationStatus_Rejected;
  15112. }
  15113. else
  15114. {
  15115. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15117. isSuccess = ConfigurationStatus_Accepted;
  15118. }
  15119. }
  15120. else
  15121. {
  15122. isSuccess = ConfigurationStatus_Rejected;
  15123. }
  15124. }
  15125. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15126. {
  15127. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15128. {
  15129. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15130. isSuccess = ConfigurationStatus_Accepted;
  15131. }
  15132. else
  15133. {
  15134. isSuccess = ConfigurationStatus_Rejected;
  15135. }
  15136. }
  15137. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15138. {
  15139. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15140. {
  15141. check_ascii = value[0];
  15142. if( (check_ascii < 48) || (check_ascii > 57) )
  15143. {
  15144. isSuccess = ConfigurationStatus_Rejected;
  15145. }
  15146. else
  15147. {
  15148. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15149. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15150. isSuccess = ConfigurationStatus_Accepted;
  15151. }
  15152. }
  15153. else
  15154. {
  15155. isSuccess = ConfigurationStatus_Rejected;
  15156. }
  15157. }
  15158. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15159. {
  15160. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15161. {
  15162. check_ascii = value[0];
  15163. if( (check_ascii < 48) || (check_ascii > 57) )
  15164. {
  15165. isSuccess = ConfigurationStatus_Rejected;
  15166. }
  15167. else
  15168. {
  15169. if((atoi(value) == 0) || (atoi(value) >= 3))
  15170. {
  15171. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15172. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15173. isSuccess = ConfigurationStatus_Accepted;
  15174. }
  15175. else
  15176. {
  15177. isSuccess = ConfigurationStatus_Rejected;
  15178. }
  15179. }
  15180. }
  15181. else
  15182. {
  15183. isSuccess = ConfigurationStatus_Rejected;
  15184. }
  15185. }
  15186. if(strcmp(key, "MinimumStatusDuration") == 0)
  15187. {
  15188. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15189. {
  15190. check_ascii = value[0];
  15191. if( (check_ascii < 48) || (check_ascii > 57) )
  15192. {
  15193. isSuccess = ConfigurationStatus_Rejected;
  15194. }
  15195. else
  15196. {
  15197. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15198. {
  15199. isSuccess = ConfigurationStatus_Rejected;
  15200. }
  15201. else
  15202. {
  15203. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15205. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15206. isSuccess = ConfigurationStatus_Accepted;
  15207. }
  15208. }
  15209. }
  15210. else
  15211. {
  15212. isSuccess = ConfigurationStatus_Rejected;
  15213. }
  15214. }
  15215. if(strcmp(key, "NumberOfConnectors") == 0)
  15216. {
  15217. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15218. {
  15219. check_ascii = value[0];
  15220. if( (check_ascii < 48) || (check_ascii > 57) )
  15221. {
  15222. isSuccess = ConfigurationStatus_Rejected;
  15223. }
  15224. else
  15225. {
  15226. //Charger.ResetRetries = Integer.parseInt(value);
  15227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15228. isSuccess = ConfigurationStatus_Accepted;
  15229. }
  15230. }
  15231. else
  15232. {
  15233. isSuccess = ConfigurationStatus_Rejected;
  15234. }
  15235. }
  15236. if(strcmp(key, "ResetRetries") == 0)
  15237. {
  15238. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15239. {
  15240. check_ascii = value[0];
  15241. if( (check_ascii < 48) || (check_ascii > 57) )
  15242. {
  15243. isSuccess = ConfigurationStatus_Rejected;
  15244. }
  15245. else
  15246. {
  15247. //Charger.ResetRetries = Integer.parseInt(value);
  15248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15249. isSuccess = ConfigurationStatus_Accepted;
  15250. }
  15251. }
  15252. else
  15253. {
  15254. isSuccess = ConfigurationStatus_Rejected;
  15255. }
  15256. }
  15257. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15258. {
  15259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15260. {
  15261. strcpy(str, (const char*)value);
  15262. for(int i = 0; str[i]; i++)
  15263. {
  15264. str[i] = tolower(str[i]);
  15265. }
  15266. if(strcmp(str, "notapplicable")== 0)
  15267. {
  15268. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15269. isSuccess = ConfigurationStatus_Accepted;
  15270. }
  15271. else if(strcmp(str, "unknown")== 0)
  15272. {
  15273. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15274. isSuccess = ConfigurationStatus_Accepted;
  15275. }
  15276. else if(strcmp(str, "rst")== 0)
  15277. {
  15278. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15279. isSuccess = ConfigurationStatus_Accepted;
  15280. }
  15281. else if(strcmp(str, "rts")== 0)
  15282. {
  15283. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15284. isSuccess = ConfigurationStatus_Accepted;
  15285. }
  15286. else if(strcmp(str, "srt")== 0)
  15287. {
  15288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15289. isSuccess = ConfigurationStatus_Accepted;
  15290. }
  15291. else if(strcmp(str, "str")== 0)
  15292. {
  15293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15294. isSuccess = ConfigurationStatus_Accepted;
  15295. }
  15296. else if(strcmp(str, "trs")== 0)
  15297. {
  15298. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15299. isSuccess = ConfigurationStatus_Accepted;
  15300. }
  15301. else if(strcmp(str, "tsr")== 0)
  15302. {
  15303. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15304. isSuccess = ConfigurationStatus_Accepted;
  15305. }
  15306. else
  15307. {
  15308. isSuccess = ConfigurationStatus_Rejected;
  15309. }
  15310. }
  15311. else
  15312. {
  15313. isSuccess = ConfigurationStatus_Rejected;
  15314. }
  15315. }
  15316. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15317. {
  15318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15319. {
  15320. check_ascii = value[0];
  15321. if( (check_ascii < 48) || (check_ascii > 57) )
  15322. {
  15323. isSuccess = ConfigurationStatus_Rejected;
  15324. }
  15325. else
  15326. {
  15327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15328. isSuccess = ConfigurationStatus_Accepted;
  15329. }
  15330. }
  15331. else
  15332. {
  15333. isSuccess = ConfigurationStatus_Rejected;
  15334. }
  15335. }
  15336. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15337. {
  15338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15339. {
  15340. strcpy(str, (const char*)value);
  15341. for(int i = 0; str[i]; i++)
  15342. {
  15343. str[i] = tolower(str[i]);
  15344. }
  15345. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15347. isSuccess = ConfigurationStatus_Accepted;
  15348. }
  15349. else
  15350. {
  15351. isSuccess = ConfigurationStatus_Rejected;
  15352. }
  15353. }
  15354. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15355. {
  15356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15357. {
  15358. strcpy(str, (const char*)value);
  15359. for(int i = 0; str[i]; i++)
  15360. {
  15361. str[i] = tolower(str[i]);
  15362. }
  15363. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15365. isSuccess = ConfigurationStatus_Accepted;
  15366. }
  15367. else
  15368. {
  15369. isSuccess = ConfigurationStatus_Rejected;
  15370. }
  15371. }
  15372. if(strcmp(key, "StopTxnAlignedData") == 0)
  15373. {
  15374. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15375. {
  15376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15377. isSuccess = ConfigurationStatus_Accepted;
  15378. }
  15379. else
  15380. {
  15381. isSuccess = ConfigurationStatus_Rejected;
  15382. }
  15383. }
  15384. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15385. {
  15386. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15387. {
  15388. check_ascii = value[0];
  15389. if( (check_ascii < 48) || (check_ascii > 57) )
  15390. {
  15391. isSuccess = ConfigurationStatus_Rejected;
  15392. }
  15393. else
  15394. {
  15395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15396. isSuccess = ConfigurationStatus_Accepted;
  15397. }
  15398. }
  15399. else
  15400. {
  15401. isSuccess = ConfigurationStatus_Rejected;
  15402. }
  15403. }
  15404. if(strcmp(key, "StopTxnSampledData") == 0)
  15405. {
  15406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15407. {
  15408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15409. isSuccess = ConfigurationStatus_Accepted;
  15410. }
  15411. else
  15412. {
  15413. isSuccess = ConfigurationStatus_Rejected;
  15414. }
  15415. }
  15416. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15417. {
  15418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15419. {
  15420. check_ascii = value[0];
  15421. if( (check_ascii < 48) || (check_ascii > 57) )
  15422. {
  15423. isSuccess = ConfigurationStatus_Rejected;
  15424. }
  15425. else
  15426. {
  15427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15428. isSuccess = ConfigurationStatus_Accepted;
  15429. }
  15430. }
  15431. else
  15432. {
  15433. isSuccess = ConfigurationStatus_Rejected;
  15434. }
  15435. }
  15436. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15437. {
  15438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15439. {
  15440. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15441. isSuccess = ConfigurationStatus_Accepted;
  15442. }
  15443. else
  15444. {
  15445. isSuccess = ConfigurationStatus_Rejected;
  15446. }
  15447. }
  15448. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15449. {
  15450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15451. {
  15452. check_ascii = value[0];
  15453. if( (check_ascii < 48) || (check_ascii > 57) )
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. else
  15458. {
  15459. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15460. isSuccess = ConfigurationStatus_Accepted;
  15461. }
  15462. }
  15463. else
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. }
  15468. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15469. {
  15470. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15471. {
  15472. check_ascii = value[0];
  15473. if( (check_ascii < 48) || (check_ascii > 57) )
  15474. {
  15475. isSuccess = ConfigurationStatus_Rejected;
  15476. }
  15477. else
  15478. {
  15479. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15481. TransactionMessageAttemptsValue = atoi(value);
  15482. isSuccess = ConfigurationStatus_Accepted;
  15483. }
  15484. }
  15485. else
  15486. {
  15487. isSuccess = ConfigurationStatus_Rejected;
  15488. }
  15489. }
  15490. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15491. {
  15492. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15493. {
  15494. check_ascii = value[0];
  15495. if( (check_ascii < 48) || (check_ascii > 57) )
  15496. {
  15497. isSuccess = ConfigurationStatus_Rejected;
  15498. }
  15499. else
  15500. {
  15501. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15502. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15503. TransactionMessageRetryIntervalValue = atoi(value);
  15504. isSuccess = ConfigurationStatus_Accepted;
  15505. }
  15506. }
  15507. else
  15508. {
  15509. isSuccess = ConfigurationStatus_Rejected;
  15510. }
  15511. }
  15512. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15513. {
  15514. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15515. {
  15516. strcpy(str, (const char*)value);
  15517. for(int i = 0; str[i]; i++)
  15518. {
  15519. str[i] = tolower(str[i]);
  15520. }
  15521. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15522. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15523. isSuccess = ConfigurationStatus_Accepted;
  15524. }
  15525. else
  15526. {
  15527. isSuccess = ConfigurationStatus_Rejected;
  15528. }
  15529. }
  15530. if(strcmp(key, "WebSocketPingInterval") == 0)
  15531. {
  15532. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15533. {
  15534. check_ascii = value[0];
  15535. if( (check_ascii < 48) || (check_ascii > 57) )
  15536. {
  15537. isSuccess = ConfigurationStatus_Rejected;
  15538. }
  15539. else
  15540. {
  15541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15542. isSuccess = ConfigurationStatus_Accepted;
  15543. if((atoi(value) == 0) || (atoi(value) >= 10))
  15544. {
  15545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15546. isSuccess = ConfigurationStatus_Accepted;
  15547. }
  15548. else
  15549. isSuccess = ConfigurationStatus_Rejected;
  15550. }
  15551. }
  15552. else
  15553. {
  15554. isSuccess = ConfigurationStatus_Rejected;
  15555. }
  15556. }
  15557. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15558. {
  15559. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15560. {
  15561. strcpy(str, (const char*)value);
  15562. for(int i = 0; str[i]; i++)
  15563. {
  15564. str[i] = tolower(str[i]);
  15565. }
  15566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15567. isSuccess = ConfigurationStatus_Accepted;
  15568. }
  15569. else
  15570. {
  15571. isSuccess = ConfigurationStatus_Rejected;
  15572. }
  15573. }
  15574. if(strcmp(key, "AuthorizationKey") == 0)
  15575. {
  15576. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15577. {
  15578. strcpy(str, (const char*)value);
  15579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15580. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15581. isSuccess = ConfigurationStatus_Accepted;
  15582. }
  15583. else
  15584. {
  15585. isSuccess = ConfigurationStatus_Rejected;
  15586. }
  15587. }
  15588. if(strcmp(key, "SecurityProfile") == 0)
  15589. {
  15590. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15591. {
  15592. check_ascii = value[0];
  15593. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15594. {
  15595. isSuccess = ConfigurationStatus_Rejected;
  15596. }
  15597. else if(check_ascii == 0x33)
  15598. {
  15599. isSuccess = NotSupported;
  15600. }
  15601. else
  15602. {
  15603. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15604. {
  15605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15606. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15607. isSuccess = ConfigurationStatus_Accepted;
  15608. }
  15609. else
  15610. isSuccess = ConfigurationStatus_Rejected;
  15611. }
  15612. }
  15613. else
  15614. {
  15615. isSuccess = ConfigurationStatus_Rejected;
  15616. }
  15617. }
  15618. if(strcmp(key, "DefaultPrice") == 0)
  15619. {
  15620. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15621. {
  15622. strcpy(str, (const char*)value);
  15623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15624. isSuccess = ConfigurationStatus_Accepted;
  15625. }
  15626. else
  15627. {
  15628. isSuccess = ConfigurationStatus_Rejected;
  15629. }
  15630. }
  15631. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15632. {
  15633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15634. {
  15635. strcpy(str, (const char*)value);
  15636. for(int i = 0; str[i]; i++)
  15637. {
  15638. str[i] = tolower(str[i]);
  15639. }
  15640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15641. isSuccess = ConfigurationStatus_Accepted;
  15642. }
  15643. else
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. }
  15648. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15649. {
  15650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15651. {
  15652. strcpy(str, (const char*)value);
  15653. for(int i = 0; str[i]; i++)
  15654. {
  15655. str[i] = tolower(str[i]);
  15656. }
  15657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15658. isSuccess = ConfigurationStatus_Accepted;
  15659. }
  15660. else
  15661. {
  15662. isSuccess = ConfigurationStatus_Rejected;
  15663. }
  15664. }
  15665. if(strcmp(key, "SystemUptimeSec") == 0)
  15666. {
  15667. isSuccess = NotSupported;
  15668. }
  15669. if(strcmp(key, "FreeVend") == 0)
  15670. {
  15671. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15672. {
  15673. strcpy(str, (const char*)value);
  15674. for(int i = 0; str[i]; i++)
  15675. {
  15676. str[i] = tolower(str[i]);
  15677. }
  15678. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15680. isSuccess = ConfigurationStatus_Accepted;
  15681. }
  15682. else
  15683. {
  15684. isSuccess = ConfigurationStatus_Rejected;
  15685. }
  15686. }
  15687. if(strcmp(key, "OcppServer") == 0)
  15688. {
  15689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15690. {
  15691. strcpy(str, (const char*)value);
  15692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15693. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15694. isSuccess = ConfigurationStatus_Accepted;
  15695. }
  15696. else
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. }
  15701. if(strcmp(key, "MaintainServer") == 0)
  15702. {
  15703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15704. {
  15705. strcpy(str, (const char*)value);
  15706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15707. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15708. isSuccess = ConfigurationStatus_Accepted;
  15709. }
  15710. else
  15711. {
  15712. isSuccess = ConfigurationStatus_Rejected;
  15713. }
  15714. }
  15715. #if 0
  15716. //For OCPP Test Case
  15717. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15718. {
  15719. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15720. {
  15721. strcpy(str, (const char*)value);
  15722. for(int i = 0; str[i]; i++)
  15723. {
  15724. str[i] = tolower(str[i]);
  15725. }
  15726. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15727. isSuccess = ConfigurationStatus_Accepted;
  15728. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15729. }
  15730. else
  15731. {
  15732. isSuccess = ConfigurationStatus_Rejected;
  15733. }
  15734. }
  15735. #endif
  15736. #if 1
  15737. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15738. {
  15739. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15740. {
  15741. strcpy(str, (const char*)value);
  15742. for(int i = 0; str[i]; i++)
  15743. {
  15744. str[i] = tolower(str[i]);
  15745. }
  15746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15747. isSuccess = ConfigurationStatus_Accepted;
  15748. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15749. }
  15750. else
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. }
  15755. #endif
  15756. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15757. {
  15758. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15759. {
  15760. check_ascii = value[0];
  15761. if( (check_ascii < 48) || (check_ascii > 57) )
  15762. {
  15763. isSuccess = ConfigurationStatus_Rejected;
  15764. }
  15765. else
  15766. {
  15767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15768. isSuccess = ConfigurationStatus_Accepted;
  15769. }
  15770. }
  15771. else
  15772. {
  15773. isSuccess = ConfigurationStatus_Rejected;
  15774. }
  15775. }
  15776. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15777. {
  15778. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15779. {
  15780. check_ascii = value[0];
  15781. if( (check_ascii < 48) || (check_ascii > 57) )
  15782. {
  15783. isSuccess = ConfigurationStatus_Rejected;
  15784. }
  15785. else
  15786. {
  15787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15788. isSuccess = ConfigurationStatus_Accepted;
  15789. }
  15790. }
  15791. else
  15792. {
  15793. isSuccess = ConfigurationStatus_Rejected;
  15794. }
  15795. }
  15796. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15797. {
  15798. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15799. {
  15800. strcpy(str, (const char*)value);
  15801. for(int i = 0; str[i]; i++)
  15802. {
  15803. str[i] = tolower(str[i]);
  15804. }
  15805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15806. isSuccess = ConfigurationStatus_Accepted;
  15807. }
  15808. else
  15809. {
  15810. isSuccess = ConfigurationStatus_Rejected;
  15811. }
  15812. }
  15813. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15814. {
  15815. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15816. {
  15817. check_ascii = value[0];
  15818. if( (check_ascii < 48) || (check_ascii > 57) )
  15819. {
  15820. isSuccess = ConfigurationStatus_Rejected;
  15821. }
  15822. else
  15823. {
  15824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15825. isSuccess = ConfigurationStatus_Accepted;
  15826. }
  15827. }
  15828. else
  15829. {
  15830. isSuccess = ConfigurationStatus_Rejected;
  15831. }
  15832. }
  15833. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15834. {
  15835. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15836. {
  15837. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15838. isSuccess = ConfigurationStatus_Accepted;
  15839. }
  15840. else
  15841. {
  15842. isSuccess = ConfigurationStatus_Rejected;
  15843. }
  15844. }
  15845. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15846. {
  15847. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15848. {
  15849. check_ascii = value[0];
  15850. if( (check_ascii < 48) || (check_ascii > 57) )
  15851. {
  15852. isSuccess = ConfigurationStatus_Rejected;
  15853. }
  15854. else
  15855. {
  15856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15857. isSuccess = ConfigurationStatus_Accepted;
  15858. }
  15859. }
  15860. else
  15861. {
  15862. isSuccess = ConfigurationStatus_Rejected;
  15863. }
  15864. }
  15865. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15866. {
  15867. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15868. {
  15869. strcpy(str, (const char*)value);
  15870. for(int i = 0; str[i]; i++)
  15871. {
  15872. str[i] = tolower(str[i]);
  15873. }
  15874. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15875. isSuccess = ConfigurationStatus_Accepted;
  15876. }
  15877. else
  15878. {
  15879. isSuccess = ConfigurationStatus_Rejected;
  15880. }
  15881. }
  15882. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15883. {
  15884. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15885. {
  15886. check_ascii = value[0];
  15887. if( (check_ascii < 48) || (check_ascii > 57) )
  15888. {
  15889. isSuccess = ConfigurationStatus_Rejected;
  15890. }
  15891. else
  15892. {
  15893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15894. isSuccess = ConfigurationStatus_Accepted;
  15895. }
  15896. }
  15897. else
  15898. {
  15899. isSuccess = ConfigurationStatus_Rejected;
  15900. }
  15901. }
  15902. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15903. return isSuccess;
  15904. }
  15905. int TransactionMessageAttemptsGet(void)
  15906. {
  15907. return TransactionMessageAttemptsValue;
  15908. }
  15909. int FirstHeartBeatResponse(void)
  15910. {
  15911. return FirstHeartBeat;
  15912. }
  15913. int TransactionMessageRetryIntervalGet(void)
  15914. {
  15915. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15916. }
  15917. int ReadHttpStatus(int sock)
  15918. {
  15919. //char c;
  15920. char buff[1024]="",*ptr=buff+1;
  15921. int bytes_received, status;
  15922. DEBUG_INFO("Begin Response ..\n");
  15923. while((bytes_received = recv(sock, ptr, 1, 0))){
  15924. if(bytes_received==-1){
  15925. perror("ReadHttpStatus");
  15926. exit(1);
  15927. }
  15928. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15929. ptr++;
  15930. }
  15931. *ptr=0;
  15932. ptr=buff+1;
  15933. sscanf(ptr,"%*s %d ", &status);
  15934. DEBUG_INFO("%s\n",ptr);
  15935. DEBUG_INFO("status=%d\n",status);
  15936. DEBUG_INFO("End Response ..\n");
  15937. return (bytes_received>0)?status:0;
  15938. }
  15939. //the only filed that it parsed is 'Content-Length'
  15940. int ParseHeader(int sock)
  15941. {
  15942. //char c;
  15943. char buff[1024]="",*ptr=buff+4;
  15944. int bytes_received;
  15945. DEBUG_INFO("Begin HEADER ..\n");
  15946. while((bytes_received = recv(sock, ptr, 1, 0))){
  15947. if(bytes_received==-1){
  15948. perror("Parse Header");
  15949. exit(1);
  15950. }
  15951. if(
  15952. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15953. (ptr[-1]=='\r') && (*ptr=='\n' )
  15954. ) break;
  15955. ptr++;
  15956. }
  15957. *ptr=0;
  15958. ptr=buff+4;
  15959. //printf("%s",ptr);
  15960. if(bytes_received){
  15961. ptr=strstr(ptr,"Content-Length:");
  15962. if(ptr){
  15963. sscanf(ptr,"%*s %d",&bytes_received);
  15964. }else
  15965. bytes_received=-1; //unknown size
  15966. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15967. }
  15968. DEBUG_INFO("End HEADER ..\n");
  15969. return bytes_received ;
  15970. }
  15971. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15972. {
  15973. int result = TRUE;
  15974. char rmFileCmd[100]={0};
  15975. char FilePath[100]={0};
  15976. char ftpbuf[200];
  15977. int systemresult;
  15978. sprintf(FilePath,"/mnt/%s",filename);
  15979. system("ping 8.8.8.8 &");
  15980. if((access(FilePath,F_OK))!=-1)
  15981. {
  15982. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15983. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15984. system(rmFileCmd);
  15985. }
  15986. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15987. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15988. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15989. systemresult = system(ftpbuf);
  15990. if(systemresult != 0)
  15991. {
  15992. DEBUG_INFO("http DownLoad error!\n");
  15993. result = FALSE;
  15994. }
  15995. system("pkill ping");
  15996. return result;
  15997. }
  15998. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15999. {
  16000. int result = TRUE;
  16001. char rmFileCmd[100]={0};
  16002. char FilePath[100]={0};
  16003. char ftpbuf[200];
  16004. int systemresult;
  16005. sprintf(FilePath,"/mnt/%s",filename);
  16006. system("ping 8.8.8.8 &");
  16007. if((access(FilePath,F_OK))!=-1)
  16008. {
  16009. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16010. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16011. system(rmFileCmd);
  16012. }
  16013. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16014. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16015. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16016. systemresult = system(ftpbuf);
  16017. if(systemresult != 0)
  16018. {
  16019. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16020. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16021. systemresult = system(ftpbuf);
  16022. if(systemresult != 0)
  16023. {
  16024. DEBUG_WARN("wget error!\n");
  16025. result = FALSE;
  16026. }
  16027. }
  16028. system("pkill ping");
  16029. return result;
  16030. }
  16031. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16032. {
  16033. char rmFileCmd[100]={0};
  16034. char FilePath[100]={0};
  16035. char buf[512];
  16036. int systemresult = 0;
  16037. //DEBUG_INFO("filename=%s\n",filename);
  16038. //DEBUG_INFO("url=%s\n",url);
  16039. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16040. if((access(FilePath,F_OK))!=-1)
  16041. {
  16042. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16043. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16044. system(rmFileCmd);
  16045. }
  16046. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16047. if(fp == NULL)
  16048. {
  16049. DEBUG_INFO("log is NULL\n");
  16050. return FALSE;
  16051. }
  16052. else
  16053. {
  16054. fprintf(fp, "%s\n", url);
  16055. fprintf(fp, "%s\n", filename);
  16056. fclose(fp);
  16057. }
  16058. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16059. if(phpFP == NULL)
  16060. {
  16061. DEBUG_INFO("PHP upload fail.\n");
  16062. return FALSE;
  16063. }
  16064. else
  16065. {
  16066. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16067. {
  16068. if(strstr(buf, "result") != NULL)
  16069. {
  16070. sscanf(buf, "result: %d", &systemresult);
  16071. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16072. }
  16073. }
  16074. pclose(phpFP);
  16075. }
  16076. if(systemresult != 1)
  16077. {
  16078. DEBUG_INFO("HTTP upload error!\n");
  16079. return FALSE;
  16080. }
  16081. return TRUE;
  16082. }
  16083. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16084. {
  16085. int result = FALSE;
  16086. char ftpbuf[200];
  16087. int systemresult;
  16088. /*
  16089. // Domaind name transfer to IP address
  16090. struct hostent* server;
  16091. char *IPbuffer;
  16092. server = gethostbyname(location);
  16093. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16094. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16095. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16096. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16097. systemresult = system(ftpbuf);
  16098. if(systemresult != 0)
  16099. {
  16100. DEBUG_INFO("ftpput error!\n");
  16101. }
  16102. else
  16103. {
  16104. result = TRUE;
  16105. DEBUG_INFO("ftpput OK!\n");
  16106. }
  16107. return result;
  16108. }
  16109. int GetOcppServerURL()
  16110. {
  16111. int result = FALSE;
  16112. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16113. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16114. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16115. struct yuarel url;
  16116. char urlStr[512];
  16117. // OCPPPH only
  16118. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16119. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16120. {
  16121. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16122. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16123. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16124. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16125. if(yuarel_parse(&url, urlStr) != -1)
  16126. {
  16127. sprintf(OcppProtocol, "%s", url.scheme);
  16128. sprintf(OcppHost, "%s", url.host);
  16129. if(url.path == NULL)
  16130. OcppTempPath[0] = '\0';
  16131. else
  16132. sprintf(OcppTempPath, "%s", url.path);
  16133. if(url.port == 0)
  16134. {
  16135. if(strcmp(OcppProtocol, "wss") == 0)
  16136. OcppPort = 443;
  16137. else
  16138. OcppPort = 80;
  16139. }
  16140. else
  16141. OcppPort = url.port;
  16142. result = TRUE;
  16143. }
  16144. }
  16145. else
  16146. {
  16147. strcpy(OcppHost,"");
  16148. }
  16149. return result;
  16150. }
  16151. int GetOcppPath()
  16152. {
  16153. int result = FALSE;
  16154. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16155. {
  16156. if(OcppTempPath == NULL)
  16157. {
  16158. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16159. }
  16160. else
  16161. {
  16162. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16163. }
  16164. result = TRUE;
  16165. goto End;
  16166. }
  16167. else
  16168. {
  16169. strcpy(OcppPath,"");
  16170. }
  16171. End:
  16172. return result;
  16173. }
  16174. int GetOcppPort()
  16175. {
  16176. return OcppPort;
  16177. }
  16178. int GetOcppConnStatus(void)
  16179. {
  16180. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16181. }
  16182. void SetOcppConnStatus(uint8_t status)
  16183. {
  16184. ShmOCPP16DataPH->OcppConnStatus = status;
  16185. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16186. }
  16187. int GetHeartBeatWithNOResponse(void)
  16188. {
  16189. return HeartBeatWithNOResponse;
  16190. }
  16191. void SetHeartBeatWithNOResponse(void)
  16192. {
  16193. HeartBeatWithNOResponse = 0;
  16194. }
  16195. void GetStartTransactionIdTag(int gun_index)
  16196. {
  16197. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16198. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16199. }
  16200. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16201. {
  16202. char ch;
  16203. FILE *fptr1;
  16204. int temptransactionId;
  16205. char str[100]={0};
  16206. temptransactionId = 0;
  16207. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16208. {
  16209. DEBUG_INFO("IdTag is empty.\n");
  16210. return temptransactionId;
  16211. }
  16212. /*------ Read the file ----------------*/
  16213. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16214. if (!fptr1)
  16215. {
  16216. DEBUG_INFO("QueueTransactionId file open error.\n");
  16217. //printf(" File not found or unable to open the input file!!\n");
  16218. return temptransactionId;
  16219. }
  16220. ch=fgetc(fptr1);
  16221. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16222. rewind(fptr1);
  16223. if(ch!=EOF)
  16224. {
  16225. // printf("%c",ch);
  16226. while (fgets(str, 100, fptr1) != NULL)
  16227. {
  16228. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16229. if(str[0]=='\0')
  16230. {
  16231. break;
  16232. }
  16233. char *revbuf[8] = {0}; // Variable store string split
  16234. int num = 0;// Quantity after string split
  16235. DEBUG_INFO("Transaction queue data= %s\n", str);
  16236. splitstring(str,",",revbuf,&num); // String split
  16237. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16238. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16239. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16240. DEBUG_INFO("------------------------------\n");
  16241. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16242. {
  16243. if(isStopTransaction)
  16244. {
  16245. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16246. {
  16247. temptransactionId = atoi(revbuf[2]);
  16248. //break;
  16249. }
  16250. }
  16251. else
  16252. {
  16253. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16254. {
  16255. temptransactionId = atoi(revbuf[2]);
  16256. //break;
  16257. }
  16258. }
  16259. }
  16260. }
  16261. }
  16262. else
  16263. DEBUG_INFO("EOF\n");
  16264. fclose(fptr1);
  16265. /*------- End of reading ---------------*/
  16266. return temptransactionId;
  16267. }
  16268. void SetTransactionIdZero(int transactionId)
  16269. {
  16270. char ch;
  16271. FILE *fptr1, *fptr2;
  16272. int temptransactionId = 0;
  16273. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16274. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16275. if (!fptr1)
  16276. {
  16277. //printf(" File not found or unable to open the input file!!\n");
  16278. return ;
  16279. }
  16280. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16281. if (!fptr2)
  16282. {
  16283. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16284. fclose(fptr1);
  16285. return ;
  16286. }
  16287. ch=fgetc(fptr1);
  16288. rewind(fptr1);
  16289. if(ch!=EOF)
  16290. {
  16291. // copy all contents to the temporary file except the specific line
  16292. while (fgets(str, 100, fptr1) != NULL)
  16293. {
  16294. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16295. if(str[0]=='\0')
  16296. {
  16297. break;
  16298. }
  16299. char *revbuf[8] = {0};
  16300. int num = 0;
  16301. strcpy(strtemp, str);
  16302. splitstring(str,",",revbuf,&num);
  16303. if(revbuf[2][0] != '\0')
  16304. {
  16305. temptransactionId = atoi(revbuf[2]);
  16306. if(transactionId != temptransactionId)
  16307. {
  16308. fprintf(fptr2, "%s\n", strtemp);
  16309. }
  16310. }
  16311. }
  16312. }
  16313. fclose(fptr1);
  16314. fclose(fptr2);
  16315. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16316. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16317. /*------ Read the file ----------------*/
  16318. }
  16319. int InternetDisconnect(void)
  16320. {
  16321. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16322. }
  16323. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16324. void storeTempStopTransaction(int gun_index)
  16325. {
  16326. char guid[37]={0};
  16327. int tempIndex = 0;
  16328. char TempStopTransaction[256];
  16329. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16330. DEBUG_INFO("storeTempStopTransaction...\n");
  16331. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16332. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16333. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16336. {
  16337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16338. {
  16339. tempIndex = ((gun_index==2) ? 1: 0);
  16340. }
  16341. else
  16342. {
  16343. tempIndex = gun_index;
  16344. }
  16345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16346. {
  16347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16348. {
  16349. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16350. }
  16351. }// END OF CHAdeMO_QUANTITY
  16352. }
  16353. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16354. {
  16355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16356. {
  16357. tempIndex = ((gun_index==2) ? 1: 0);
  16358. }
  16359. else
  16360. {
  16361. tempIndex = gun_index;
  16362. }
  16363. for (int index = 0; index < CCS_QUANTITY; index++)
  16364. {
  16365. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16366. {
  16367. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16368. }
  16369. }// END OF CCS_QUANTITY
  16370. }
  16371. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16372. {
  16373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16374. {
  16375. tempIndex = ((gun_index==2) ? 1: 0);
  16376. }
  16377. else
  16378. {
  16379. tempIndex = gun_index;
  16380. }
  16381. for (int index = 0; index < GB_QUANTITY; index++)
  16382. {
  16383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16384. {
  16385. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16386. }
  16387. }// END OF GB_QUANTITY
  16388. }
  16389. else if(gunType[gun_index] == GUN_TYPE_DO)
  16390. {
  16391. tempIndex = gun_index;
  16392. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16393. {
  16394. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16395. {
  16396. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16397. }
  16398. }
  16399. }
  16400. else
  16401. {
  16402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16403. {
  16404. tempIndex = 2;
  16405. }
  16406. else
  16407. {
  16408. tempIndex = gun_index;
  16409. }
  16410. for (int index = 0; index < AC_QUANTITY; index++)
  16411. {
  16412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16413. {
  16414. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16415. }
  16416. }// END OF AC_QUANTITY
  16417. }
  16418. //Stop Transaction Time
  16419. struct timeval tmnow;
  16420. struct tm *tm;
  16421. char buf[28];//, usec_buf[6];
  16422. gettimeofday(&tmnow, NULL);
  16423. time_t t;
  16424. t = time(NULL);
  16425. /*UTC time and date*/
  16426. tm = gmtime(&t);
  16427. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16429. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16430. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16431. random_uuid(guid);
  16432. /***********************************transactionData******************************************************/
  16433. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16435. //=================================
  16436. //1. Transaction_Begin
  16437. //=================================
  16438. //============================== Energy.Active.Import.Interval ===========================================
  16439. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16440. {
  16441. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16443. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16444. 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*/]);
  16445. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16446. 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))
  16447. {
  16448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16449. }
  16450. else
  16451. {
  16452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16453. }
  16454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16456. }
  16457. //=================================
  16458. //2. Transaction_End
  16459. //=================================
  16460. //2.1====================================== Current.Import L1 ==============================================
  16461. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16462. {
  16463. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16464. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16465. {
  16466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16467. {
  16468. tempIndex = ((gun_index==2) ? 1: 0);
  16469. }
  16470. else
  16471. {
  16472. tempIndex = gun_index;
  16473. }
  16474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16475. {
  16476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16477. {
  16478. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16479. }
  16480. }// End of for CHAdeMO_QUANTITY
  16481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16482. }
  16483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16484. {
  16485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16486. {
  16487. tempIndex = ((gun_index==2) ? 1: 0);
  16488. }
  16489. else
  16490. {
  16491. tempIndex = gun_index;
  16492. }
  16493. for (int index = 0; index < CCS_QUANTITY; index++)
  16494. {
  16495. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16496. {
  16497. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16498. }
  16499. }// End of for CCS_QUANTITY
  16500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16501. }
  16502. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16503. {
  16504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16505. {
  16506. tempIndex = ((gun_index==2) ? 1: 0);
  16507. }
  16508. else
  16509. {
  16510. tempIndex = gun_index;
  16511. }
  16512. for (int index = 0; index < GB_QUANTITY; index++)
  16513. {
  16514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16515. {
  16516. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16517. }
  16518. }// End of for GB_QUANTITY
  16519. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16520. }
  16521. else if(gunType[gun_index] == GUN_TYPE_DO)
  16522. {
  16523. tempIndex = gun_index;
  16524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16525. {
  16526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16527. {
  16528. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16529. }
  16530. }
  16531. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16532. }
  16533. else
  16534. {
  16535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16536. {
  16537. tempIndex = 2;
  16538. }
  16539. else
  16540. {
  16541. tempIndex = gun_index;
  16542. }
  16543. for (int index = 0; index < AC_QUANTITY; index++)
  16544. {
  16545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16546. {
  16547. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16548. }
  16549. }// End of for AC_QUANTITY
  16550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16551. }
  16552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16555. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16558. }
  16559. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16560. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16561. {
  16562. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16564. {
  16565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16566. {
  16567. tempIndex = ((gun_index==2) ? 1: 0);
  16568. }
  16569. else
  16570. {
  16571. tempIndex = gun_index;
  16572. }
  16573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16574. {
  16575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16576. {
  16577. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16578. }
  16579. }// END OF CHAdeMO_QUANTITY
  16580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16581. }
  16582. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16583. {
  16584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16585. {
  16586. tempIndex = ((gun_index==2) ? 1: 0);
  16587. }
  16588. else
  16589. {
  16590. tempIndex = gun_index;
  16591. }
  16592. for (int index = 0; index < CCS_QUANTITY; index++)
  16593. {
  16594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16595. {
  16596. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16597. }
  16598. }// END OF CCS_QUANTITY
  16599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16600. }
  16601. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16602. {
  16603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16604. {
  16605. tempIndex = ((gun_index==2) ? 1: 0);
  16606. }
  16607. else
  16608. {
  16609. tempIndex = gun_index;
  16610. }
  16611. for (int index = 0; index < GB_QUANTITY; index++)
  16612. {
  16613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16614. {
  16615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16616. }
  16617. }// END OF GB_QUANTITY
  16618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16619. }
  16620. else if(gunType[gun_index] == GUN_TYPE_DO)
  16621. {
  16622. tempIndex = gun_index;
  16623. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16624. {
  16625. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16626. {
  16627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16628. }
  16629. }
  16630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16631. }
  16632. else
  16633. {
  16634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16635. {
  16636. tempIndex = 2;
  16637. }
  16638. else
  16639. {
  16640. tempIndex = gun_index;
  16641. }
  16642. for (int index = 0; index < AC_QUANTITY; index++)
  16643. {
  16644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16645. {
  16646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16647. }
  16648. }// END OF AC_QUANTITY
  16649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16650. }
  16651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16654. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16657. }
  16658. //2.3====================================== Power.Active.Import =========================================
  16659. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16660. {
  16661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16662. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16663. {
  16664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16665. {
  16666. tempIndex = ((gun_index==2) ? 1: 0);
  16667. }
  16668. else
  16669. {
  16670. tempIndex = gun_index;
  16671. }
  16672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16673. {
  16674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16675. {
  16676. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16677. }
  16678. } // End for CHAdeMO_QUANTITY
  16679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16680. }
  16681. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16682. {
  16683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16684. {
  16685. tempIndex = ((gun_index==2) ? 1: 0);
  16686. }
  16687. else
  16688. {
  16689. tempIndex = gun_index;
  16690. }
  16691. for (int index = 0; index < CCS_QUANTITY; index++)
  16692. {
  16693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16694. {
  16695. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16696. }
  16697. } // END for CCS_QUANTITY
  16698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16699. }
  16700. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16701. {
  16702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16703. {
  16704. tempIndex = ((gun_index==2) ? 1: 0);
  16705. }
  16706. else
  16707. {
  16708. tempIndex = gun_index;
  16709. }
  16710. for (int index = 0; index < GB_QUANTITY; index++)
  16711. {
  16712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16713. {
  16714. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16715. }
  16716. }// END for GB_QUANTITY
  16717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16718. }
  16719. else if(gunType[gun_index] == GUN_TYPE_DO)
  16720. {
  16721. tempIndex = gun_index;
  16722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16723. {
  16724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16725. {
  16726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16727. }
  16728. }
  16729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16730. }
  16731. else
  16732. {
  16733. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16734. {
  16735. tempIndex = 2;
  16736. }
  16737. else
  16738. {
  16739. tempIndex = gun_index;
  16740. }
  16741. for (int index = 0; index < AC_QUANTITY; index++)
  16742. {
  16743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16744. {
  16745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16746. }
  16747. } // END for AC_QUANTITY
  16748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16749. }
  16750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16753. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16756. }
  16757. //2.4====================================== Voltage L1 ====================================================
  16758. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16759. {
  16760. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16761. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16762. {
  16763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16764. {
  16765. tempIndex = ((gun_index==2) ? 1: 0);
  16766. }
  16767. else
  16768. {
  16769. tempIndex = gun_index;
  16770. }
  16771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16772. {
  16773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16774. {
  16775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16776. }
  16777. } // END OF FOR CHAdeMO_QUANTITY
  16778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16779. }
  16780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16781. {
  16782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16783. {
  16784. tempIndex = ((gun_index==2) ? 1: 0);
  16785. }
  16786. else
  16787. {
  16788. tempIndex = gun_index;
  16789. }
  16790. for (int index = 0; index < CCS_QUANTITY; index++)
  16791. {
  16792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16793. {
  16794. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16795. }
  16796. } // END OF FOR CCS_QUANTITY
  16797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16798. }
  16799. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16800. {
  16801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16802. {
  16803. tempIndex = ((gun_index==2) ? 1: 0);
  16804. }
  16805. else
  16806. {
  16807. tempIndex = gun_index;
  16808. }
  16809. for (int index = 0; index < GB_QUANTITY; index++)
  16810. {
  16811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16812. {
  16813. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16814. }
  16815. } // END OF FOR GB_QUANTITY
  16816. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16817. }
  16818. else if(gunType[gun_index] == GUN_TYPE_DO)
  16819. {
  16820. tempIndex = gun_index;
  16821. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16822. {
  16823. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16824. {
  16825. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16826. }
  16827. }
  16828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16829. }
  16830. else
  16831. {
  16832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16833. {
  16834. tempIndex = 2;
  16835. }
  16836. else
  16837. {
  16838. tempIndex = gun_index;
  16839. }
  16840. for (int index = 0; index < AC_QUANTITY; index++)
  16841. {
  16842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16843. {
  16844. 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
  16845. }
  16846. } // END OF FOR AC_QUANTITY
  16847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16848. }
  16849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16852. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16855. }
  16856. //2.5============================================== End SoC =========================================================
  16857. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16858. {
  16859. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16860. 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))
  16861. {
  16862. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16863. {
  16864. tempIndex = ((gun_index==2) ? 1: 0);
  16865. }
  16866. else
  16867. {
  16868. tempIndex = gun_index;
  16869. }
  16870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16871. {
  16872. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16873. {
  16874. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16875. {
  16876. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16877. }
  16878. }
  16879. }
  16880. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16881. {
  16882. for (int index = 0; index < CCS_QUANTITY; index++)
  16883. {
  16884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16885. {
  16886. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16887. }
  16888. }
  16889. }
  16890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16891. {
  16892. for (int index = 0; index < GB_QUANTITY; index++)
  16893. {
  16894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16895. {
  16896. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16897. }
  16898. }
  16899. }
  16900. else if(gunType[gun_index] == GUN_TYPE_DO)
  16901. {
  16902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16903. {
  16904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16905. {
  16906. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16907. }
  16908. }
  16909. }
  16910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16912. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16916. } // END FOR DC CASE
  16917. }
  16918. //2.6====================================== Current.Import L2 ==============================================
  16919. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16920. {
  16921. // AC 3 phase L2 current
  16922. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16923. {
  16924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16925. {
  16926. tempIndex = 2;
  16927. }
  16928. else
  16929. {
  16930. tempIndex = gun_index;
  16931. }
  16932. for (int index = 0; index < AC_QUANTITY; index++)
  16933. {
  16934. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16935. {
  16936. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16937. }
  16938. }// End of for AC_QUANTITY
  16939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16940. }
  16941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16946. }
  16947. //2.7====================================== Current.Import L3 ==============================================
  16948. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16949. {
  16950. // AC 3 phase L3 current
  16951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16952. {
  16953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16954. {
  16955. tempIndex = 2;
  16956. }
  16957. else
  16958. {
  16959. tempIndex = gun_index;
  16960. }
  16961. for (int index = 0; index < AC_QUANTITY; index++)
  16962. {
  16963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16964. {
  16965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16966. }
  16967. }// End of for AC_QUANTITY
  16968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16969. }
  16970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16975. }
  16976. //2.9====================================== Voltage L2 ====================================================
  16977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16978. {
  16979. // AC 3 phase L2 volatge
  16980. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16981. {
  16982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16983. {
  16984. tempIndex = 2;
  16985. }
  16986. else
  16987. {
  16988. tempIndex = gun_index;
  16989. }
  16990. for (int index = 0; index < AC_QUANTITY; index++)
  16991. {
  16992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16993. {
  16994. 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
  16995. }
  16996. } // END OF FOR AC_QUANTITY
  16997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16998. }
  16999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17004. }
  17005. //2.10====================================== Voltage L3 ====================================================
  17006. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17007. {
  17008. // AC 3 phase L3 volatge
  17009. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17010. {
  17011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17012. {
  17013. tempIndex = 2;
  17014. }
  17015. else
  17016. {
  17017. tempIndex = gun_index;
  17018. }
  17019. for (int index = 0; index < AC_QUANTITY; index++)
  17020. {
  17021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17022. {
  17023. 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
  17024. }
  17025. } // END OF FOR AC_QUANTITY
  17026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17027. }
  17028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17033. }
  17034. //====================== Start SoC ================================
  17035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17036. {
  17037. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17038. 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))
  17039. {
  17040. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17041. {
  17042. tempIndex = ((gun_index==2) ? 1: 0);
  17043. }
  17044. else
  17045. {
  17046. tempIndex = gun_index;
  17047. }
  17048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17049. {
  17050. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17051. {
  17052. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17053. {
  17054. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17055. }
  17056. }
  17057. }
  17058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17059. {
  17060. for (int index = 0; index < CCS_QUANTITY; index++)
  17061. {
  17062. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17063. {
  17064. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17065. }
  17066. }
  17067. }
  17068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17069. {
  17070. for (int index = 0; index < GB_QUANTITY; index++)
  17071. {
  17072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17073. {
  17074. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17075. }
  17076. }
  17077. }
  17078. else if(gunType[gun_index] == GUN_TYPE_DO)
  17079. {
  17080. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17081. {
  17082. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17083. {
  17084. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17085. }
  17086. }
  17087. }
  17088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17094. } // END FOR DC CASE
  17095. }
  17096. //======================================== Message create ==============================================
  17097. json_object *StopTransaction = json_object_new_object();
  17098. json_object *transactionDatas = json_object_new_array();
  17099. json_object *sampledValues = json_object_new_array();
  17100. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17101. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17102. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17103. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17104. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17105. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17106. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17107. {
  17108. json_object *transactionData = json_object_new_object();
  17109. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17110. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17111. {
  17112. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17113. {
  17114. json_object *sampledValue = json_object_new_object();
  17115. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17116. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17117. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17118. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17119. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17120. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17121. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17122. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17123. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17124. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17125. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17126. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17127. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17128. json_object_array_add(sampledValues, sampledValue);
  17129. }
  17130. }
  17131. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17132. json_object_array_add(transactionDatas, transactionData);
  17133. }
  17134. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17135. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17136. ,MESSAGE_TYPE_CALL
  17137. ,guid
  17138. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17139. json_object_put(StopTransaction);
  17140. // Check File "TempStopTransaction" Exist
  17141. if((access(TempStopTransaction,F_OK))!=-1)
  17142. {
  17143. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17144. fclose(fopen(TempStopTransaction, "w"));
  17145. }
  17146. else
  17147. {
  17148. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17149. FILE *log = fopen(TempStopTransaction, "w+");
  17150. if(log == NULL)
  17151. {
  17152. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17153. return ;
  17154. }
  17155. else
  17156. {
  17157. fclose(log);
  17158. }
  17159. }
  17160. //Add TempStopTransaction | Update TempStopTransaction
  17161. // open file for writing
  17162. FILE *outfile;
  17163. outfile = fopen (TempStopTransaction, "a");
  17164. //DEBUG_INFO("data = %s\n", queuedata);
  17165. fputs(queuedata, outfile);
  17166. fputs("\n", outfile);
  17167. fclose (outfile);
  17168. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17169. }
  17170. void checkTempStopTransaction(int gun_index)
  17171. {
  17172. FILE *fptr1;
  17173. char ch;
  17174. char str[QUEUE_MESSAGE_LENGTH]={0};
  17175. char guid[37]={0};
  17176. char tempdata[65]={0};
  17177. char connectorStr[2]={0};
  17178. char TempStopTransaction[256];
  17179. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17180. fptr1 = fopen(TempStopTransaction, "r");
  17181. //TempStopTransaction格式: 槍號,StopTransaction封包
  17182. if (!fptr1)
  17183. {
  17184. //printf(" File not found or unable to open the input file!!\n");
  17185. return ;
  17186. }
  17187. ch=fgetc(fptr1);
  17188. //printf(" Now the content of the file %s is : \n",fname);
  17189. rewind(fptr1);
  17190. if(ch!=EOF)
  17191. {
  17192. // copy all contents to the temporary file except the specific line
  17193. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17194. {
  17195. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17196. if(str[0]=='\0')
  17197. {
  17198. break;
  17199. }
  17200. //TempStopTransaction格式: 槍號,StopTransaction封包
  17201. strncpy(connectorStr, str, 1);
  17202. if(atoi(connectorStr) != (gun_index+1))
  17203. {
  17204. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17205. fclose(fptr1);
  17206. return ;
  17207. }
  17208. //random_uuid(guid);
  17209. strncpy(guid, str+6, 36); //copy guid
  17210. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17211. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17212. {
  17213. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17214. }
  17215. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17216. OCPP_insert_transaction_msg(NO, str);
  17217. memset(str,0,ARRAY_SIZE(str));
  17218. }
  17219. }
  17220. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17221. fclose(fptr1);
  17222. remove(TempStopTransaction); // remove the original file
  17223. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17224. }
  17225. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17226. {
  17227. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17228. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17229. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17230. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17231. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17232. }
  17233. int GetWebSocketPingInterval(void)
  17234. {
  17235. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17236. }
  17237. int GetServerSign(void)
  17238. {
  17239. return server_sign;
  17240. }
  17241. uint8_t GetOcppSecurityProfile()
  17242. {
  17243. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17244. }
  17245. void GetOcppChargerBoxId(uint8_t *data)
  17246. {
  17247. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17248. }
  17249. void GetOcppSecurityPassword(uint8_t *data)
  17250. {
  17251. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17252. }
  17253. void SetOcppVersion(uint8_t *version)
  17254. {
  17255. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17256. DEBUG_INFO("ocpp version: %s\n", version);
  17257. if(strstr((char*)version, "ocpp1.6") != NULL)
  17258. {
  17259. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17260. }
  17261. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17262. {
  17263. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17264. system("pkill OcppBackend");
  17265. }
  17266. }
  17267. void SetServerSign(int value)
  17268. {
  17269. server_sign = value;
  17270. }
  17271. int GetBootNotificationInterval(void)
  17272. {
  17273. return BootNotificationInterval;
  17274. }
  17275. int GetInternetConn(void)
  17276. {
  17277. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17278. }
  17279. int GetBackendConnectionTimeout(void)
  17280. {
  17281. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17282. }
  17283. int isConnectorInitMode(int gun_index)
  17284. {
  17285. int tempIndex = 0;
  17286. int result = TRUE;
  17287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17289. {
  17290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17291. {
  17292. tempIndex = ((gun_index==2) ? 1: 0);
  17293. }
  17294. else
  17295. {
  17296. tempIndex = gun_index;
  17297. }
  17298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17299. {
  17300. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17301. {
  17302. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17303. } //end of the same index
  17304. }//end of for CHAdeMO_QUANTITY
  17305. }
  17306. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17307. {
  17308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17309. {
  17310. tempIndex = ((gun_index==2) ? 1: 0);
  17311. }
  17312. else
  17313. {
  17314. tempIndex = gun_index;
  17315. }
  17316. for (int index = 0; index < CCS_QUANTITY; index++)
  17317. {
  17318. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17319. {
  17320. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17321. } //end of the same index
  17322. } // end of for CCS_QUANTITY
  17323. }
  17324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17325. {
  17326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17327. {
  17328. tempIndex = ((gun_index==2) ? 1: 0);
  17329. }
  17330. else
  17331. {
  17332. tempIndex = gun_index;
  17333. }
  17334. for (int index = 0; index < GB_QUANTITY; index++)
  17335. {
  17336. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17337. {
  17338. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17339. } //end of the same index
  17340. } // end of for GB_QUANTITY
  17341. }
  17342. else if(gunType[gun_index] == GUN_TYPE_DO)
  17343. {
  17344. tempIndex = gun_index;
  17345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17346. {
  17347. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17348. {
  17349. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17350. } //end of the same index
  17351. }
  17352. }
  17353. else
  17354. {
  17355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17356. {
  17357. tempIndex = 2;
  17358. }
  17359. else
  17360. {
  17361. tempIndex = gun_index;
  17362. }
  17363. for (int index = 0; index < AC_QUANTITY; index++)
  17364. {
  17365. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17366. {
  17367. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17368. }//end of the same index
  17369. }//end of for AC_QUANTITY
  17370. }
  17371. return result;
  17372. }
  17373. void refreshProcDogTimer()
  17374. {
  17375. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17376. }
  17377. void InitialSystemValue(void)
  17378. {
  17379. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17380. locallistVersion=0;
  17381. BootNotificationInterval = 0;
  17382. authorizeRetryTimes = 0;
  17383. GunStatusInterval = 10;
  17384. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17385. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17386. //Hear Beat
  17387. HeartBeatWithNOResponse = 0;
  17388. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17389. FirstHeartBeat = 0;
  17390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17391. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17392. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17393. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17394. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17395. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17396. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17397. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17398. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17399. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17400. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17401. //Status && ConnectorPlugIn Setting
  17402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17403. {
  17404. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17405. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17406. }
  17407. for (int index = 0; index < CCS_QUANTITY; index++)
  17408. {
  17409. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17410. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17411. }
  17412. for (int index = 0; index < GB_QUANTITY; index++)
  17413. {
  17414. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17415. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17416. }
  17417. for (int index = 0; index < AC_QUANTITY; index++)
  17418. {
  17419. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17420. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17421. }
  17422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17423. {
  17424. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17425. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17426. }
  17427. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17428. {
  17429. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17430. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17431. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17432. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17433. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17434. }
  17435. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17436. refreshStartTimer(&clientTime.Heartbeat);
  17437. sleep(1);
  17438. }
  17439. void LWS_Send(char *str)
  17440. {
  17441. //=====================================================
  17442. // Check InternetConn 0: disconnected, 1: connected
  17443. //====================================================
  17444. if(GetOcppConnStatus() == 0)
  17445. {
  17446. DEBUG_INFO("offline now !!!\n");
  17447. return;
  17448. }
  17449. // Only disable isWebsocketSendable operation initiated by charger
  17450. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17451. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17452. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17453. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17454. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17455. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17456. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17457. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17458. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17459. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17460. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17461. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17462. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17463. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17464. {
  17465. isWebsocketSendable = 0;
  17466. }
  17467. pthread_mutex_lock(&lock_send);
  17468. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17469. sprintf((char *)SendBuffer, "%s", str);
  17470. SendBufLen = strlen(str);
  17471. pthread_mutex_unlock(&lock_send);
  17472. lws_callback_on_writable(wsi_client);
  17473. //lws_service(context, 0);
  17474. //sleep(1);
  17475. }
  17476. void LWS_SendNow(char *str)
  17477. {
  17478. //=====================================================
  17479. // Check InternetConn 0: disconnected, 1: connected
  17480. //====================================================
  17481. if(GetOcppConnStatus() == 0)
  17482. {
  17483. DEBUG_INFO("offline now !!!\n");
  17484. return;
  17485. }
  17486. // Only disable isWebsocketSendable operation initiated by charger
  17487. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17488. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17489. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17490. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17491. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17492. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17493. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17494. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17495. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17496. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17497. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17498. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17499. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17500. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17501. {
  17502. isWebsocketSendable = 0;
  17503. }
  17504. pthread_mutex_lock(&lock_send);
  17505. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17506. sprintf((char *)SendBuffer, "%s", str);
  17507. SendBufLen = strlen(str);
  17508. pthread_mutex_unlock(&lock_send);
  17509. lws_callback_on_writable(wsi_client);
  17510. lws_service(context, 0);
  17511. //sleep(1);
  17512. }