MessageHandler.c 904 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433
  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 MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. 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);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. 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);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. 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));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '0');", txId, creditNo, deductResult, isDonateInvoice, amount, vemData);
  680. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  681. {
  682. result = FAIL;
  683. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  684. }
  685. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. return result;
  692. }
  693. int OCPP_update_deduct_info(int txId, char *creditNo)
  694. {
  695. int result = PASS;
  696. char* errMsg = NULL;
  697. char sqlStr[8192];
  698. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  699. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  700. {
  701. result = FAIL;
  702. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  703. }
  704. return result;
  705. }
  706. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  707. {
  708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s}",
  711. atoi(columnValue[1]),
  712. columnValue[2],
  713. atoi(columnValue[3])==1?"true":"false",
  714. atoi(columnValue[4])==1?"true":"false",
  715. columnValue[5]);
  716. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  717. return 0;
  718. }
  719. void OCPP_query_deduct_info()
  720. {
  721. int rc = 0;
  722. char sql[100];
  723. char zErrMsg[100];
  724. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  725. /* Execute SQL statement */
  726. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  727. if( rc != SQLITE_OK )
  728. {
  729. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  730. }
  731. }
  732. //==========================================
  733. // Check time passed since today
  734. //==========================================
  735. long long DiffTimebWithNow(struct timeb ST)
  736. {
  737. //return milli-second
  738. struct timeb ET;
  739. long long StartTime,StopTime;
  740. ftime(&ET);
  741. StartTime=(long long)ST.time;
  742. StopTime=(long long)ET.time;
  743. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  744. }
  745. int getTimePassSinceToday(uint8_t gun_index)
  746. {
  747. int result = -1;
  748. static time_t lastTime[4];
  749. time_t t;
  750. struct tm *tmStartToday;
  751. struct timeb tbStartToday;
  752. t=time(NULL);
  753. if(difftime(t, lastTime[gun_index])>0)
  754. {
  755. tmStartToday=localtime(&t);
  756. tmStartToday->tm_hour = 0;
  757. tmStartToday->tm_min = 0;
  758. tmStartToday->tm_sec = 0;
  759. tbStartToday.time = mktime(tmStartToday);
  760. tbStartToday.millitm = 0;
  761. result = DiffTimebWithNow(tbStartToday)/1000;
  762. lastTime[gun_index] = t;
  763. }
  764. return result;
  765. }
  766. void getNowDatetime(uint8_t *data)
  767. {
  768. time_t t = time(NULL);
  769. struct tm tm = *localtime(&t);
  770. 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);
  771. }
  772. int syncDateTimeRTC(uint8_t *data)
  773. {
  774. struct ParsingResult
  775. {
  776. int result;
  777. int scanedElement;
  778. int year;
  779. int month;
  780. int mday;
  781. int hour;
  782. int min;
  783. int sec;
  784. int tz_hour;
  785. int tz_min;
  786. float minSec;
  787. }result;
  788. struct tm tmOrg;
  789. struct tm *tmTarget;
  790. struct timeb tbTarget;
  791. char buf[128];
  792. memset(&result, 0x00, sizeof(struct ParsingResult));
  793. result.result = PASS;
  794. if(strstr((char*)data, ".") != NULL)
  795. {
  796. // Original data with mini second
  797. if(strstr((char*)data, "Z") != NULL)
  798. {
  799. // Original data with Z
  800. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  801. &result.year,
  802. &result.month,
  803. &result.mday,
  804. &result.hour,
  805. &result.min,
  806. &result.sec,
  807. &result.minSec);
  808. }
  809. else
  810. {
  811. // Original data without Z
  812. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  813. &result.year,
  814. &result.month,
  815. &result.mday,
  816. &result.hour,
  817. &result.min,
  818. &result.sec,
  819. &result.minSec,
  820. &result.tz_hour,
  821. &result.tz_min);
  822. }
  823. }
  824. else
  825. {
  826. // Original data without mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec);
  837. }
  838. else
  839. {
  840. // Original data without Z
  841. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  842. &result.year,
  843. &result.month,
  844. &result.mday,
  845. &result.hour,
  846. &result.min,
  847. &result.sec,
  848. &result.tz_hour,
  849. &result.tz_min);
  850. }
  851. }
  852. tmOrg.tm_year = result.year - 1900;
  853. tmOrg.tm_mon = result.month - 1;
  854. tmOrg.tm_mday = result.mday;
  855. tmOrg.tm_hour = result.hour;
  856. tmOrg.tm_min = result.min;
  857. tmOrg.tm_sec = result.sec;
  858. tmOrg.tm_gmtoff = 0;
  859. tbTarget.time = mktime(&tmOrg);
  860. tbTarget.timezone = 0;
  861. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  862. tmTarget = gmtime(&tbTarget.time);
  863. 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);
  864. //DEBUG_INFO(" org date time: %s\n", data);
  865. //DEBUG_INFO("parse date time: %s\n", buf);
  866. system(buf);
  867. system("/sbin/hwclock -w --systohc");
  868. if(result.scanedElement < 6)
  869. result.result = FAIL;
  870. return result.result;
  871. }
  872. //==========================================
  873. // GetCompositeSchedule logic related function
  874. //==========================================
  875. int DiffTimebSec(struct timeb ST, struct timeb ET)
  876. {
  877. //return milli-second
  878. unsigned int StartTime,StopTime;
  879. StartTime=(unsigned int)ST.time;
  880. StopTime=(unsigned int)ET.time;
  881. return (StopTime-StartTime);
  882. }
  883. int DiffTimebWithNowSec(struct timeb ST)
  884. {
  885. //return milli-second
  886. struct timeb ET;
  887. unsigned int StartTime,StopTime;
  888. ftime(&ET);
  889. StartTime=(unsigned int)ST.time;
  890. StopTime=(unsigned int)ET.time;
  891. return (StopTime-StartTime);
  892. }
  893. int getStartStop(uint8_t *start, uint8_t *stop)
  894. {
  895. int result = -1;
  896. struct tm tmStart;
  897. struct timeb tbStart;
  898. struct tm tmStop;
  899. struct timeb tbStop;
  900. 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) &&
  901. (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))
  902. {
  903. //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);
  904. //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);
  905. tmStart.tm_year -= 1900;
  906. tmStart.tm_mon -= 1;
  907. tbStart.time = mktime(&tmStart);
  908. tbStart.millitm = 0;
  909. tmStop.tm_year -= 1900;
  910. tmStop.tm_mon -= 1;
  911. tbStop.time = mktime(&tmStop);
  912. tbStop.millitm = 0;
  913. result = DiffTimebSec(tbStart, tbStop);
  914. //DEBUG_INFO("getStartStop(): %d\n", result);
  915. }
  916. else
  917. {
  918. DEBUG_WARN("Start or stop date parsing error.\r\n");
  919. }
  920. return result;
  921. }
  922. int isOvertNow(uint8_t *start)
  923. {
  924. int result = NO;
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. }parsingResult;
  939. struct tm tmStart;
  940. struct timeb tbStart;
  941. if(strstr((char*)start, ".") != NULL)
  942. {
  943. // Original data with mini second
  944. if(strstr((char*)start, "Z") != NULL)
  945. {
  946. // Original data with Z
  947. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  948. &parsingResult.year,
  949. &parsingResult.month,
  950. &parsingResult.mday,
  951. &parsingResult.hour,
  952. &parsingResult.min,
  953. &parsingResult.sec,
  954. &parsingResult.minSec);
  955. }
  956. else
  957. {
  958. // Original data without Z
  959. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  960. &parsingResult.year,
  961. &parsingResult.month,
  962. &parsingResult.mday,
  963. &parsingResult.hour,
  964. &parsingResult.min,
  965. &parsingResult.sec,
  966. &parsingResult.minSec,
  967. &parsingResult.tz_hour,
  968. &parsingResult.tz_min);
  969. }
  970. }
  971. else
  972. {
  973. // Original data without mini second
  974. if(strstr((char*)start, "Z") != NULL)
  975. {
  976. // Original data with Z
  977. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  978. &parsingResult.year,
  979. &parsingResult.month,
  980. &parsingResult.mday,
  981. &parsingResult.hour,
  982. &parsingResult.min,
  983. &parsingResult.sec);
  984. }
  985. else
  986. {
  987. // Original data without Z
  988. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  989. &parsingResult.year,
  990. &parsingResult.month,
  991. &parsingResult.mday,
  992. &parsingResult.hour,
  993. &parsingResult.min,
  994. &parsingResult.sec,
  995. &parsingResult.tz_hour,
  996. &parsingResult.tz_min);
  997. }
  998. }
  999. if(parsingResult.scanedElement >= 6)
  1000. {
  1001. tmStart.tm_year = parsingResult.year - 1900;
  1002. tmStart.tm_mon = parsingResult.month - 1;
  1003. tmStart.tm_mday = parsingResult.mday;
  1004. tmStart.tm_hour = parsingResult.hour;
  1005. tmStart.tm_min = parsingResult.min;
  1006. tmStart.tm_sec = parsingResult.sec;
  1007. tmStart.tm_gmtoff = 0;
  1008. tbStart.time = mktime(&tmStart);
  1009. tbStart.timezone = 0;
  1010. tbStart.millitm = 0;
  1011. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1012. if(DiffTimebWithNowSec(tbStart) <= 0)
  1013. result = NO;
  1014. else
  1015. result = YES;
  1016. }
  1017. else
  1018. {
  1019. DEBUG_WARN("Start date parsing error.\n");
  1020. }
  1021. return result;
  1022. }
  1023. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1024. {
  1025. int result = -1;
  1026. struct tm tmStart;
  1027. struct timeb tbStart;
  1028. struct tm tmStop;
  1029. struct timeb tbStop;
  1030. 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) &&
  1031. (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))
  1032. {
  1033. tmStart.tm_year -= 1900;
  1034. tmStart.tm_mon -= 1;
  1035. tbStart.time = mktime(&tmStart);
  1036. tbStart.millitm = 0;
  1037. tmStop.tm_year -= 1900;
  1038. tmStop.tm_mon -= 1;
  1039. tbStop.time = mktime(&tmStop);
  1040. tbStop.millitm = 0;
  1041. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1042. }
  1043. return result;
  1044. }
  1045. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1046. {
  1047. FILE *fp;
  1048. char profileFileName[128];
  1049. char *line = NULL;
  1050. size_t len = 0;
  1051. time_t CurrentTime;
  1052. struct tm *tmComposite;
  1053. struct StructChargingProfile maxProfile;
  1054. uint8_t limitMax=0;
  1055. int compositePeriodIdx = 0;
  1056. CurrentTime = time(NULL);
  1057. tmComposite=localtime(&CurrentTime);
  1058. 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);
  1059. if(isUnitA)
  1060. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1061. else
  1062. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1063. compositeProfile->ChargingSchedule.Duration = durationReq;
  1064. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1065. {
  1066. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1067. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1069. }
  1070. compositeProfile->ChargingProfileId = 0;
  1071. compositeProfile->StackLevel = 99 ;
  1072. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1073. maxProfile.ChargingProfileId = -1;
  1074. maxProfile.ChargingSchedule.Duration = -1;
  1075. system("rm -f /tmp/*.json");
  1076. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1077. // Search max profile
  1078. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1079. if((access(profileFileName, F_OK))!=-1)
  1080. {
  1081. fp = fopen(profileFileName, "r");
  1082. while(getline(&line, &len, fp) != -1)
  1083. {
  1084. json_object *obj = NULL;
  1085. obj = json_tokener_parse(line);
  1086. if(is_error(obj))
  1087. {
  1088. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1089. }
  1090. else
  1091. {
  1092. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1093. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1094. )
  1095. {
  1096. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1097. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. )
  1099. {
  1100. struct tm tmFrom, tmTo;
  1101. struct timeb tbFrom, tbTo;
  1102. 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) &&
  1103. (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))
  1104. {
  1105. tmFrom.tm_year -= 1900;
  1106. tmFrom.tm_mon -= 1;
  1107. tbFrom.time = mktime(&tmFrom);
  1108. tmTo.tm_year -= 1900;
  1109. tmTo.tm_mon -= 1;
  1110. tbTo.time = mktime(&tmTo);
  1111. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1112. {
  1113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1114. {
  1115. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1118. }
  1119. maxProfile.ChargingProfileId = -1;
  1120. maxProfile.StackLevel = -1;
  1121. if(maxProfile.ChargingProfileId == -1)
  1122. DEBUG_INFO("MaxProfile found.\n");
  1123. else
  1124. DEBUG_INFO("MaxProfile updated.\n");
  1125. // Required item
  1126. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1127. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1128. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1129. if(isUnitA)
  1130. {
  1131. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1132. 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++)
  1133. {
  1134. 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"));
  1135. 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?
  1136. 3:
  1137. 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")));
  1138. 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")));
  1139. }
  1140. }
  1141. else
  1142. {
  1143. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1144. 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++)
  1145. {
  1146. 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"));
  1147. 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?
  1148. 3:
  1149. 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")));
  1150. 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));
  1151. }
  1152. }
  1153. // Optional item
  1154. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1155. {
  1156. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1157. }
  1158. else
  1159. {
  1160. sprintf((char*)maxProfile.ValidFrom, " ");
  1161. }
  1162. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. {
  1164. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1165. }
  1166. else
  1167. {
  1168. sprintf((char*)maxProfile.ValidTo, " ");
  1169. }
  1170. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1171. {
  1172. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1173. }
  1174. else
  1175. {
  1176. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1177. }
  1178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1179. {
  1180. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1181. }
  1182. else
  1183. {
  1184. maxProfile.TransactionId = -1;
  1185. }
  1186. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1187. {
  1188. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1189. }
  1190. else
  1191. {
  1192. maxProfile.ChargingSchedule.Duration = 86400;
  1193. }
  1194. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1195. {
  1196. 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")));
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1201. }
  1202. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1203. {
  1204. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1205. }
  1206. else
  1207. {
  1208. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. else
  1214. {
  1215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1216. {
  1217. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1218. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1220. }
  1221. maxProfile.ChargingProfileId = -1;
  1222. maxProfile.StackLevel = -1;
  1223. if(maxProfile.ChargingProfileId == -1)
  1224. DEBUG_INFO("MaxProfile found.\n");
  1225. else
  1226. DEBUG_INFO("MaxProfile updated.\n");
  1227. // Required item
  1228. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1229. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1230. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1231. if(isUnitA)
  1232. {
  1233. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1234. 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++)
  1235. {
  1236. 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"));
  1237. 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?
  1238. 3:
  1239. 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")));
  1240. 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")));
  1241. }
  1242. }
  1243. else
  1244. {
  1245. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1246. 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++)
  1247. {
  1248. 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"));
  1249. 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?
  1250. 3:
  1251. 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")));
  1252. 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));
  1253. }
  1254. }
  1255. // Optional item
  1256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1257. {
  1258. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1259. }
  1260. else
  1261. {
  1262. sprintf((char*)maxProfile.ValidFrom, " ");
  1263. }
  1264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1265. {
  1266. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1267. }
  1268. else
  1269. {
  1270. sprintf((char*)maxProfile.ValidTo, " ");
  1271. }
  1272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1273. {
  1274. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1275. }
  1276. else
  1277. {
  1278. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1279. }
  1280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1281. {
  1282. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1283. }
  1284. else
  1285. {
  1286. maxProfile.TransactionId = -1;
  1287. }
  1288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1289. {
  1290. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1291. }
  1292. else
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = 86400;
  1295. }
  1296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1297. {
  1298. 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")));
  1299. }
  1300. else
  1301. {
  1302. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1303. }
  1304. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1305. {
  1306. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1307. }
  1308. else
  1309. {
  1310. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. json_object_put(obj);
  1316. }
  1317. fclose(fp);
  1318. /*
  1319. if(maxProfile.ChargingProfileId !=-1)
  1320. {
  1321. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1322. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1323. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1324. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1325. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1326. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1327. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1328. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1329. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1330. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1331. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1333. {
  1334. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1335. {
  1336. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1337. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1338. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1339. }
  1340. }
  1341. }
  1342. else
  1343. DEBUG_INFO("MaxProfile not found.\n");
  1344. DEBUG_INFO("------------------------------------\n");*/
  1345. }
  1346. if(maxProfile.ChargingProfileId != -1)
  1347. {
  1348. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1349. {
  1350. if(maxProfile.ChargingSchedule.Duration != -1)
  1351. {
  1352. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1353. 0:
  1354. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1355. }
  1356. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1357. {
  1358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1363. if(idxPeriod > 0)
  1364. {
  1365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1366. {
  1367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1374. {
  1375. if(maxProfile.ChargingSchedule.Duration != -1)
  1376. {
  1377. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1378. }
  1379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1380. {
  1381. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1382. {
  1383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1384. if(idxPeriod > 0)
  1385. {
  1386. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1387. {
  1388. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. else
  1395. {
  1396. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1397. {
  1398. if(maxProfile.ChargingSchedule.Duration != -1)
  1399. {
  1400. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1401. 0:
  1402. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1403. }
  1404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1405. {
  1406. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1407. {
  1408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1409. 0:
  1410. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1411. if(idxPeriod > 0)
  1412. {
  1413. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1414. {
  1415. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if(maxProfile.ChargingSchedule.Duration != -1)
  1424. {
  1425. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1426. 0:
  1427. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1428. }
  1429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1430. {
  1431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1432. {
  1433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1434. 0:
  1435. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1436. if(idxPeriod > 0)
  1437. {
  1438. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1439. {
  1440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. /*
  1448. DEBUG_INFO("MaxProfile after align.\n");
  1449. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1450. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1451. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1452. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1453. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1454. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1455. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1456. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1457. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1458. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1459. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1461. {
  1462. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1463. {
  1464. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1465. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1466. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1467. }
  1468. }
  1469. DEBUG_INFO("------------------------------------\n");*/
  1470. }
  1471. // Find each profile period quantity
  1472. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1473. {
  1474. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1475. limitMax = idx+1;
  1476. }
  1477. if(maxProfile.ChargingProfileId != -1)
  1478. {
  1479. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1480. {
  1481. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1482. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1483. (maxProfile.ChargingSchedule.Duration > 0))
  1484. {
  1485. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1486. {
  1487. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1488. compositePeriodIdx++;
  1489. }
  1490. else
  1491. {
  1492. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1493. }
  1494. }
  1495. }
  1496. }
  1497. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1498. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1499. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1500. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1502. {
  1503. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1504. {
  1505. compositeProfile->ChargingProfileId = 1;
  1506. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1507. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1508. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1509. }
  1510. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1512. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1514. }
  1515. if(line)
  1516. free(line);
  1517. }
  1518. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1519. {
  1520. FILE *fp;
  1521. char profileFileName[128];
  1522. char *line = NULL;
  1523. size_t len = 0;
  1524. time_t CurrentTime;
  1525. struct tm *tmComposite;
  1526. struct StructChargingProfile maxProfile;
  1527. struct StructChargingProfile defaultTxProfile;
  1528. struct StructChargingProfile txProfile;
  1529. struct StructChargingSchedulePeriod tmpPeriod;
  1530. uint8_t limitMax=0;
  1531. uint8_t limitDef=0;
  1532. uint8_t limitTx=0;
  1533. int compositePeriodIdx = 0;
  1534. CurrentTime = time(NULL);
  1535. tmComposite=localtime(&CurrentTime);
  1536. 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);
  1537. if(isUnitA)
  1538. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1539. else
  1540. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1541. compositeProfile->ChargingSchedule.Duration = durationReq;
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1545. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1547. }
  1548. compositeProfile->ChargingProfileId = 0;
  1549. compositeProfile->StackLevel = 99 ;
  1550. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1551. maxProfile.ChargingProfileId = -1;
  1552. defaultTxProfile.ChargingProfileId = -1;
  1553. txProfile.ChargingProfileId = -1;
  1554. maxProfile.ChargingSchedule.Duration = -1;
  1555. defaultTxProfile.ChargingSchedule.Duration = -1;
  1556. txProfile.ChargingSchedule.Duration = -1;
  1557. system("rm -f /tmp/*.json");
  1558. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1559. /*
  1560. * Search valid charging profile
  1561. */
  1562. //DEBUG_INFO("====================================\n");
  1563. // Search tx profile
  1564. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1565. if((access(profileFileName, F_OK))!=-1)
  1566. {
  1567. fp = fopen(profileFileName, "r");
  1568. while(getline(&line, &len, fp) != -1)
  1569. {
  1570. json_object *obj = NULL;
  1571. obj = json_tokener_parse(line);
  1572. if(is_error(obj))
  1573. {
  1574. DEBUG_ERROR("Parse txProfile from file error.\n");
  1575. }
  1576. else
  1577. {
  1578. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1579. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1580. )
  1581. {
  1582. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1583. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1584. )
  1585. {
  1586. struct tm tmFrom, tmTo;
  1587. struct timeb tbFrom, tbTo;
  1588. 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) &&
  1589. (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))
  1590. {
  1591. tmFrom.tm_year -= 1900;
  1592. tmFrom.tm_mon -= 1;
  1593. tbFrom.time = mktime(&tmFrom);
  1594. tmTo.tm_year -= 1900;
  1595. tmTo.tm_mon -= 1;
  1596. tbTo.time = mktime(&tmTo);
  1597. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1598. {
  1599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1600. {
  1601. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1602. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1604. }
  1605. txProfile.ChargingProfileId = -1;
  1606. txProfile.StackLevel = -1;
  1607. if(txProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("TxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("TxProfile updated.\n");
  1611. // Required item
  1612. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1619. {
  1620. 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"));
  1621. 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?
  1622. 3:
  1623. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1624. 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")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1631. {
  1632. 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"));
  1633. 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?
  1634. 3:
  1635. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1636. 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));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)txProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)txProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)txProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. txProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. txProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. txProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1704. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1706. }
  1707. txProfile.ChargingProfileId = -1;
  1708. txProfile.StackLevel = -1;
  1709. if(txProfile.ChargingProfileId == -1)
  1710. DEBUG_INFO("TxProfile found.\n");
  1711. else
  1712. DEBUG_INFO("TxProfile updated.\n");
  1713. // Required item
  1714. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1715. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1716. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1717. if(isUnitA)
  1718. {
  1719. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1720. 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++)
  1721. {
  1722. 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"));
  1723. 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?
  1724. 3:
  1725. 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")));
  1726. 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")));
  1727. }
  1728. }
  1729. else
  1730. {
  1731. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1732. 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++)
  1733. {
  1734. 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"));
  1735. 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?
  1736. 3:
  1737. 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")));
  1738. 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));
  1739. }
  1740. }
  1741. // Optional item
  1742. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1743. {
  1744. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1745. }
  1746. else
  1747. {
  1748. sprintf((char*)txProfile.ValidFrom, " ");
  1749. }
  1750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1751. {
  1752. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1753. }
  1754. else
  1755. {
  1756. sprintf((char*)txProfile.ValidTo, " ");
  1757. }
  1758. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1759. {
  1760. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1761. }
  1762. else
  1763. {
  1764. sprintf((char*)txProfile.RecurrencyKind, " ");
  1765. }
  1766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1767. {
  1768. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1769. }
  1770. else
  1771. {
  1772. txProfile.TransactionId = -1;
  1773. }
  1774. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1775. {
  1776. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1777. }
  1778. else
  1779. {
  1780. txProfile.ChargingSchedule.Duration = 86400;
  1781. }
  1782. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1783. {
  1784. 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")));
  1785. }
  1786. else
  1787. {
  1788. 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));
  1789. }
  1790. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1791. {
  1792. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1793. }
  1794. else
  1795. {
  1796. txProfile.ChargingSchedule.MinChargingRate = -1;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. json_object_put(obj);
  1802. }
  1803. fclose(fp);
  1804. /*
  1805. if(txProfile.ChargingProfileId != -1)
  1806. {
  1807. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1808. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1809. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1810. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1811. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1812. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1813. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1814. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1815. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1816. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1817. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1819. {
  1820. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1821. {
  1822. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1823. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1824. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1825. }
  1826. }
  1827. }
  1828. else
  1829. DEBUG_INFO("TxProfile not found.\n");*/
  1830. }
  1831. // Search default tx profile
  1832. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1833. if((access(profileFileName, F_OK))==-1)
  1834. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1835. if((access(profileFileName, F_OK))!=-1)
  1836. {
  1837. fp = fopen(profileFileName, "r");
  1838. while(getline(&line, &len, fp) != -1)
  1839. {
  1840. json_object *obj = NULL;
  1841. obj = json_tokener_parse(line);
  1842. if(is_error(obj))
  1843. {
  1844. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1845. }
  1846. else
  1847. {
  1848. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1849. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1850. )
  1851. {
  1852. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1853. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. )
  1855. {
  1856. struct tm tmFrom, tmTo;
  1857. struct timeb tbFrom, tbTo;
  1858. 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) &&
  1859. (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))
  1860. {
  1861. tmFrom.tm_year -= 1900;
  1862. tmFrom.tm_mon -= 1;
  1863. tbFrom.time = mktime(&tmFrom);
  1864. tmTo.tm_year -= 1900;
  1865. tmTo.tm_mon -= 1;
  1866. tbTo.time = mktime(&tmTo);
  1867. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1868. {
  1869. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1870. {
  1871. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1872. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1874. }
  1875. defaultTxProfile.ChargingProfileId = -1;
  1876. defaultTxProfile.StackLevel = -1;
  1877. if(defaultTxProfile.ChargingProfileId == -1)
  1878. DEBUG_INFO("TxDefaultProfile found.\n");
  1879. else
  1880. DEBUG_INFO("TxDefaultProfile updated.\n");
  1881. // Required item
  1882. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1883. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1884. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1885. if(isUnitA)
  1886. {
  1887. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1888. 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++)
  1889. {
  1890. 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"));
  1891. 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?
  1892. 3:
  1893. 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")));
  1894. 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")));
  1895. }
  1896. }
  1897. else
  1898. {
  1899. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1900. 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++)
  1901. {
  1902. 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"));
  1903. 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?
  1904. 3:
  1905. 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")));
  1906. 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));
  1907. }
  1908. }
  1909. // Optional item
  1910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1911. {
  1912. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1913. }
  1914. else
  1915. {
  1916. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1917. }
  1918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1919. {
  1920. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1921. }
  1922. else
  1923. {
  1924. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1925. }
  1926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1927. {
  1928. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1929. }
  1930. else
  1931. {
  1932. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1933. }
  1934. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1935. {
  1936. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1937. }
  1938. else
  1939. {
  1940. defaultTxProfile.TransactionId = -1;
  1941. }
  1942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1943. {
  1944. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1945. }
  1946. else
  1947. {
  1948. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1949. }
  1950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1951. {
  1952. 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")));
  1953. }
  1954. else
  1955. {
  1956. 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));
  1957. }
  1958. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1959. {
  1960. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1961. }
  1962. else
  1963. {
  1964. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1965. }
  1966. }
  1967. }
  1968. }
  1969. else
  1970. {
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1974. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1976. }
  1977. defaultTxProfile.ChargingProfileId = -1;
  1978. defaultTxProfile.StackLevel = -1;
  1979. if(defaultTxProfile.ChargingProfileId == -1)
  1980. DEBUG_INFO("TxDefaultProfile found.\n");
  1981. else
  1982. DEBUG_INFO("TxDefaultProfile updated.\n");
  1983. // Required item
  1984. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1985. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1986. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1987. if(isUnitA)
  1988. {
  1989. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1990. 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++)
  1991. {
  1992. 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"));
  1993. 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?
  1994. 3:
  1995. 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")));
  1996. 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")));
  1997. }
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. 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++)
  2003. {
  2004. 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"));
  2005. 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?
  2006. 3:
  2007. 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")));
  2008. 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));
  2009. }
  2010. }
  2011. // Optional item
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2013. {
  2014. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2015. }
  2016. else
  2017. {
  2018. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2019. }
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2021. {
  2022. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2029. {
  2030. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2037. {
  2038. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2039. }
  2040. else
  2041. {
  2042. defaultTxProfile.TransactionId = -1;
  2043. }
  2044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2045. {
  2046. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2047. }
  2048. else
  2049. {
  2050. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2053. {
  2054. 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")));
  2055. }
  2056. else
  2057. {
  2058. 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));
  2059. }
  2060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2061. {
  2062. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2063. }
  2064. else
  2065. {
  2066. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. json_object_put(obj);
  2072. }
  2073. fclose(fp);
  2074. /*
  2075. if(defaultTxProfile.ChargingProfileId != -1)
  2076. {
  2077. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2078. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2079. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2080. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2081. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2082. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2083. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2084. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2085. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2086. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2087. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2088. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2089. {
  2090. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2091. {
  2092. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2093. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2094. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2095. }
  2096. }
  2097. }
  2098. else
  2099. DEBUG_INFO("TxDefaultProfile not found.\n");
  2100. DEBUG_INFO("------------------------------------\n");*/
  2101. }
  2102. // Search max profile
  2103. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2104. if((access(profileFileName, F_OK))!=-1)
  2105. {
  2106. fp = fopen(profileFileName, "r");
  2107. while(getline(&line, &len, fp) != -1)
  2108. {
  2109. json_object *obj = NULL;
  2110. obj = json_tokener_parse(line);
  2111. if(is_error(obj))
  2112. {
  2113. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2114. }
  2115. else
  2116. {
  2117. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2118. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2119. )
  2120. {
  2121. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2122. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2123. )
  2124. {
  2125. struct tm tmFrom, tmTo;
  2126. struct timeb tbFrom, tbTo;
  2127. 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) &&
  2128. (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))
  2129. {
  2130. tmFrom.tm_year -= 1900;
  2131. tmFrom.tm_mon -= 1;
  2132. tbFrom.time = mktime(&tmFrom);
  2133. tmTo.tm_year -= 1900;
  2134. tmTo.tm_mon -= 1;
  2135. tbTo.time = mktime(&tmTo);
  2136. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2137. {
  2138. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2139. {
  2140. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2143. }
  2144. maxProfile.ChargingProfileId = -1;
  2145. maxProfile.StackLevel = -1;
  2146. if(maxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("MaxProfile found.\n");
  2148. else
  2149. DEBUG_INFO("MaxProfile updated.\n");
  2150. // Required item
  2151. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. 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++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. 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")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)maxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)maxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. maxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. maxProfile.ChargingSchedule.Duration = 86400;
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2220. {
  2221. 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")));
  2222. }
  2223. else
  2224. {
  2225. 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));
  2226. }
  2227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2228. {
  2229. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2230. }
  2231. else
  2232. {
  2233. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. else
  2239. {
  2240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2241. {
  2242. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2243. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2244. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2245. }
  2246. maxProfile.ChargingProfileId = -1;
  2247. maxProfile.StackLevel = -1;
  2248. if(maxProfile.ChargingProfileId == -1)
  2249. DEBUG_INFO("MaxProfile found.\n");
  2250. else
  2251. DEBUG_INFO("MaxProfile updated.\n");
  2252. // Required item
  2253. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2254. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2255. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2256. if(isUnitA)
  2257. {
  2258. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2259. 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++)
  2260. {
  2261. 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"));
  2262. 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?
  2263. 3:
  2264. 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")));
  2265. 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")));
  2266. }
  2267. }
  2268. else
  2269. {
  2270. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2271. 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++)
  2272. {
  2273. 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"));
  2274. 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?
  2275. 3:
  2276. 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")));
  2277. 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));
  2278. }
  2279. }
  2280. // Optional item
  2281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2282. {
  2283. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2284. }
  2285. else
  2286. {
  2287. sprintf((char*)maxProfile.ValidFrom, " ");
  2288. }
  2289. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2290. {
  2291. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2292. }
  2293. else
  2294. {
  2295. sprintf((char*)maxProfile.ValidTo, " ");
  2296. }
  2297. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2298. {
  2299. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2300. }
  2301. else
  2302. {
  2303. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2304. }
  2305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2306. {
  2307. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2308. }
  2309. else
  2310. {
  2311. maxProfile.TransactionId = -1;
  2312. }
  2313. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2314. {
  2315. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2316. }
  2317. else
  2318. {
  2319. maxProfile.ChargingSchedule.Duration = 86400;
  2320. }
  2321. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2322. {
  2323. 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")));
  2324. }
  2325. else
  2326. {
  2327. 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));
  2328. }
  2329. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2330. {
  2331. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2332. }
  2333. else
  2334. {
  2335. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. json_object_put(obj);
  2341. }
  2342. fclose(fp);
  2343. /*
  2344. if(maxProfile.ChargingProfileId !=-1)
  2345. {
  2346. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2347. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2348. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2349. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2350. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2351. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2352. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2353. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2354. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2355. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2356. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2358. {
  2359. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2360. {
  2361. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2362. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2363. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2364. }
  2365. }
  2366. }
  2367. else
  2368. DEBUG_INFO("MaxProfile not found.\n");
  2369. DEBUG_INFO("------------------------------------\n");*/
  2370. }
  2371. /*
  2372. * Align found profile start schedule & periods
  2373. */
  2374. //DEBUG_INFO("====================================\n");
  2375. /*
  2376. // For local test usage, force modify found profile start schedule info
  2377. 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);
  2378. 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);
  2379. 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);
  2380. */
  2381. if(txProfile.ChargingProfileId != -1)
  2382. {
  2383. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2384. {
  2385. if(txProfile.ChargingSchedule.Duration != -1)
  2386. {
  2387. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2388. 0:
  2389. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2390. }
  2391. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2392. {
  2393. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2394. {
  2395. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2396. 0:
  2397. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2398. if(idxPeriod > 0)
  2399. {
  2400. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2401. {
  2402. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2409. {
  2410. if(txProfile.ChargingSchedule.Duration != -1)
  2411. {
  2412. 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?
  2413. 0:
  2414. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2415. }
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2419. {
  2420. 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?
  2421. 0:
  2422. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2423. if(idxPeriod > 0)
  2424. {
  2425. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2426. {
  2427. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. else
  2434. {
  2435. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2436. {
  2437. if(txProfile.ChargingSchedule.Duration != -1)
  2438. {
  2439. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2440. 0:
  2441. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2442. }
  2443. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2444. {
  2445. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2446. {
  2447. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2448. 0:
  2449. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2450. if(idxPeriod > 0)
  2451. {
  2452. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2453. {
  2454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. else
  2461. {
  2462. if(txProfile.ChargingSchedule.Duration != -1)
  2463. {
  2464. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2465. 0:
  2466. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2467. }
  2468. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2469. {
  2470. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2471. {
  2472. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2473. 0:
  2474. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2475. if(idxPeriod > 0)
  2476. {
  2477. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2478. {
  2479. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2480. }
  2481. }
  2482. }
  2483. }
  2484. }
  2485. }
  2486. /*
  2487. DEBUG_INFO("txProfile after align.\n");
  2488. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2489. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2490. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2491. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2492. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2493. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2494. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2495. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2496. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2497. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2498. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2499. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2500. {
  2501. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2502. {
  2503. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2504. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2505. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2506. }
  2507. }*/
  2508. }
  2509. if(defaultTxProfile.ChargingProfileId != -1)
  2510. {
  2511. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2512. {
  2513. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2514. {
  2515. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2516. 0:
  2517. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2518. }
  2519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2520. {
  2521. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2524. 0:
  2525. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2526. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2527. {
  2528. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2529. }
  2530. if(idxPeriod > 0)
  2531. {
  2532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2533. {
  2534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2535. }
  2536. }
  2537. }
  2538. }
  2539. }
  2540. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2541. {
  2542. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2543. {
  2544. 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?
  2545. 0:
  2546. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2547. }
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2551. {
  2552. 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?
  2553. 0:
  2554. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2555. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2556. {
  2557. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2558. }
  2559. if(idxPeriod > 0)
  2560. {
  2561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2562. {
  2563. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2572. {
  2573. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2574. {
  2575. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2576. 0:
  2577. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2578. }
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2582. {
  2583. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2584. 0:
  2585. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2586. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2587. {
  2588. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2589. }
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else
  2601. {
  2602. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2605. 0:
  2606. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2613. 0:
  2614. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2615. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2616. {
  2617. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2618. }
  2619. if(idxPeriod > 0)
  2620. {
  2621. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2622. {
  2623. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2624. }
  2625. }
  2626. }
  2627. }
  2628. }
  2629. }
  2630. /*
  2631. DEBUG_INFO("defaultTxProfile after align.\n");
  2632. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2633. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2634. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2635. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2636. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2637. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2638. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2639. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2640. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2641. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2642. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2644. {
  2645. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2646. {
  2647. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2648. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2649. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2650. }
  2651. }
  2652. DEBUG_INFO("------------------------------------\n");*/
  2653. }
  2654. if(maxProfile.ChargingProfileId != -1)
  2655. {
  2656. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2657. {
  2658. if(maxProfile.ChargingSchedule.Duration != -1)
  2659. {
  2660. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2661. 0:
  2662. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2663. }
  2664. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2665. {
  2666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2667. {
  2668. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2669. 0:
  2670. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2671. if(idxPeriod > 0)
  2672. {
  2673. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2674. {
  2675. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2682. {
  2683. if(maxProfile.ChargingSchedule.Duration != -1)
  2684. {
  2685. 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?
  2686. 0:
  2687. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2688. }
  2689. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2690. {
  2691. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2692. {
  2693. 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?
  2694. 0:
  2695. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2696. if(idxPeriod > 0)
  2697. {
  2698. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2699. {
  2700. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2701. }
  2702. }
  2703. }
  2704. }
  2705. }
  2706. else
  2707. {
  2708. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2709. {
  2710. if(maxProfile.ChargingSchedule.Duration != -1)
  2711. {
  2712. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2713. 0:
  2714. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2715. }
  2716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2717. {
  2718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2719. {
  2720. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2721. 0:
  2722. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2723. if(idxPeriod > 0)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2726. {
  2727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2728. }
  2729. }
  2730. }
  2731. }
  2732. }
  2733. else
  2734. {
  2735. if(maxProfile.ChargingSchedule.Duration != -1)
  2736. {
  2737. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2738. 0:
  2739. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2740. }
  2741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2742. {
  2743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2744. {
  2745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2746. 0:
  2747. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2748. if(idxPeriod > 0)
  2749. {
  2750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2751. {
  2752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. /*
  2760. DEBUG_INFO("MaxProfile after align.\n");
  2761. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2762. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2763. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2764. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2765. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2766. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2767. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2768. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2769. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2770. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2771. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2772. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2773. {
  2774. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2775. {
  2776. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2777. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2778. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2779. }
  2780. }
  2781. DEBUG_INFO("------------------------------------\n");*/
  2782. }
  2783. /*
  2784. * Merge to conposite schedule
  2785. */
  2786. //DEBUG_INFO("====================================\n");
  2787. // Find each profile period quantity
  2788. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2789. {
  2790. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2791. limitMax = idx+1;
  2792. }
  2793. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2794. {
  2795. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2796. limitDef = idx+1;
  2797. }
  2798. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2799. {
  2800. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2801. limitTx = idx+1;
  2802. }
  2803. // TxProfile found, composite schedule based on it
  2804. if(txProfile.ChargingProfileId != -1)
  2805. {
  2806. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2807. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2808. {
  2809. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2810. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2811. (txProfile.ChargingSchedule.Duration > 0))
  2812. {
  2813. if(maxProfile.ChargingProfileId != -1)
  2814. {
  2815. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2816. {
  2817. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2818. {
  2819. if((maxProfile.ChargingSchedule.Duration > 0))
  2820. {
  2821. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2822. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2823. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2824. }
  2825. else
  2826. {
  2827. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2828. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2829. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2830. }
  2831. }
  2832. if(idxMaxPeriod == (limitMax-1))
  2833. {
  2834. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2835. {
  2836. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2837. {
  2838. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2839. compositePeriodIdx++;
  2840. }
  2841. else
  2842. {
  2843. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2852. {
  2853. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2854. compositePeriodIdx++;
  2855. }
  2856. else
  2857. {
  2858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. }
  2860. }
  2861. }
  2862. if(idxTxPeriod == (limitTx-1))
  2863. {
  2864. if(defaultTxProfile.ChargingProfileId != -1)
  2865. {
  2866. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2867. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2868. {
  2869. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2871. (defaultTxProfile.ChargingSchedule.Duration>0))
  2872. {
  2873. if(maxProfile.ChargingProfileId != -1)
  2874. {
  2875. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2876. {
  2877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2878. {
  2879. if((maxProfile.ChargingSchedule.Duration > 0))
  2880. {
  2881. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2882. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2883. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2884. }
  2885. else
  2886. {
  2887. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2888. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2889. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2890. }
  2891. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2892. {
  2893. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2894. {
  2895. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2896. compositePeriodIdx++;
  2897. }
  2898. else
  2899. {
  2900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2901. }
  2902. }
  2903. // Delete duplicate period
  2904. if(compositePeriodIdx > 1)
  2905. {
  2906. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2907. {
  2908. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2909. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2910. compositePeriodIdx -= 1;
  2911. }
  2912. }
  2913. }
  2914. else
  2915. {
  2916. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2919. compositePeriodIdx++;
  2920. }
  2921. else
  2922. {
  2923. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2924. }
  2925. break;
  2926. }
  2927. }
  2928. }
  2929. else
  2930. {
  2931. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2932. {
  2933. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2934. compositePeriodIdx++;
  2935. }
  2936. else
  2937. {
  2938. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2939. }
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2948. else if(defaultTxProfile.ChargingProfileId != -1)
  2949. {
  2950. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2951. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2952. {
  2953. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2954. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2955. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2956. {
  2957. if(maxProfile.ChargingProfileId != -1)
  2958. {
  2959. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2960. {
  2961. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2962. {
  2963. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2964. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2965. if((maxProfile.ChargingSchedule.Duration > 0))
  2966. {
  2967. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2968. }
  2969. else
  2970. {
  2971. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2972. }
  2973. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2974. {
  2975. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2976. {
  2977. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2978. compositePeriodIdx++;
  2979. }
  2980. else
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2983. }
  2984. }
  2985. // Delete duplicate period
  2986. if(compositePeriodIdx > 1)
  2987. {
  2988. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2989. {
  2990. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2991. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2992. compositePeriodIdx -= 1;
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2999. {
  3000. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3001. compositePeriodIdx++;
  3002. }
  3003. else
  3004. {
  3005. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3006. }
  3007. break;
  3008. }
  3009. }
  3010. }
  3011. else
  3012. {
  3013. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3016. compositePeriodIdx++;
  3017. }
  3018. else
  3019. {
  3020. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3021. }
  3022. }
  3023. }
  3024. }
  3025. }
  3026. // Fill other period by MaxProfile
  3027. if(maxProfile.ChargingProfileId != -1)
  3028. {
  3029. if(compositePeriodIdx==0)
  3030. {
  3031. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3032. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3033. {
  3034. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3035. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3036. (maxProfile.ChargingSchedule.Duration > 0))
  3037. {
  3038. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3039. {
  3040. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3041. compositePeriodIdx++;
  3042. }
  3043. else
  3044. {
  3045. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3046. }
  3047. }
  3048. }
  3049. }
  3050. else
  3051. {
  3052. int lastCompositePeriodIdx = compositePeriodIdx;
  3053. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3054. {
  3055. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3056. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3057. (maxProfile.ChargingSchedule.Duration > 0))
  3058. {
  3059. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3062. {
  3063. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3064. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3065. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3066. }
  3067. else
  3068. {
  3069. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3070. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3071. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3072. }
  3073. }
  3074. if(tmpPeriod.Limit != -1)
  3075. {
  3076. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3077. {
  3078. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3079. {
  3080. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3081. compositePeriodIdx++;
  3082. }
  3083. else
  3084. {
  3085. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3086. }
  3087. }
  3088. // Delete duplicate period
  3089. if(compositePeriodIdx > 1)
  3090. {
  3091. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3092. {
  3093. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3094. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3095. compositePeriodIdx -= 1;
  3096. }
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. compositeProfile->ChargingSchedule.Duration = durationReq;
  3104. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3105. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3106. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3107. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3108. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3109. {
  3110. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3111. {
  3112. compositeProfile->ChargingProfileId = 1;
  3113. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3114. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3115. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3116. }
  3117. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3118. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3119. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3120. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3121. }
  3122. if(line)
  3123. free(line);
  3124. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3125. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3126. }
  3127. //==========================================
  3128. // Init all share memory
  3129. //==========================================
  3130. int InitShareMemory()
  3131. {
  3132. int result = PASS;
  3133. int MeterSMId;
  3134. //creat ShmSysConfigAndInfo
  3135. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3136. {
  3137. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3138. result = FAIL;
  3139. }
  3140. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3141. {
  3142. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3143. result = FAIL;
  3144. }
  3145. else
  3146. {}
  3147. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3148. {
  3149. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3150. result = FAIL;
  3151. }
  3152. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3153. {
  3154. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3155. result = FAIL;
  3156. }
  3157. else
  3158. {}
  3159. //creat ShmPsuData
  3160. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3161. {
  3162. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3163. result = FAIL;
  3164. }
  3165. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3166. {
  3167. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3168. result = FAIL;
  3169. }
  3170. else
  3171. {}
  3172. //link ShmOCPP16Data
  3173. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3174. {
  3175. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3176. result = FAIL;
  3177. }
  3178. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3179. {
  3180. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3181. result = FAIL;
  3182. }
  3183. else
  3184. {}
  3185. //creat ShmOCPP16DataPH
  3186. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3187. {
  3188. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3189. result = FAIL;
  3190. }
  3191. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3192. {
  3193. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3194. result = FAIL;
  3195. }
  3196. else
  3197. {}
  3198. /****************************** For Initial Settings************************************************/
  3199. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3200. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3201. // allocate Configuration memory address
  3202. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3203. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3204. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3205. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3206. //offline MeterValue Interval
  3207. TempMeterValueInterval = 0;
  3208. return result;
  3209. }
  3210. int ProcessShareMemory()
  3211. {
  3212. int result = PASS;
  3213. if(InitShareMemory() == FAIL)
  3214. {
  3215. DEBUG_ERROR("InitShareMemory NG\n");
  3216. if(ShmStatusCodeData!=NULL)
  3217. {
  3218. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3219. }
  3220. result = FAIL;
  3221. }
  3222. // Model name parsing
  3223. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3224. {
  3225. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3226. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3227. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3228. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3229. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3230. ) // 'D' means DC
  3231. {
  3232. // DO series
  3233. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3234. {
  3235. SystemInitial += 1;
  3236. gunTotalNumber += 1;
  3237. gunType[gun_index] = GUN_TYPE_DO;
  3238. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3239. {
  3240. case Gun_Type_Chademo:
  3241. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3242. break;
  3243. case Gun_Type_CCS_2:
  3244. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3245. break;
  3246. case Gun_Type_GB:
  3247. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3248. break;
  3249. case Gun_Type_AC:
  3250. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3251. break;
  3252. default:
  3253. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3254. break;
  3255. }
  3256. }
  3257. }
  3258. else
  3259. {
  3260. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3261. {
  3262. SystemInitial += 1;
  3263. gunTotalNumber += 1;
  3264. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3265. {
  3266. case Gun_Type_Chademo:
  3267. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3268. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3269. break;
  3270. case Gun_Type_CCS_2:
  3271. gunType[gun_index] = GUN_TYPE_CCS;
  3272. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3273. break;
  3274. case Gun_Type_GB:
  3275. gunType[gun_index] = GUN_TYPE_GBT;
  3276. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3277. break;
  3278. case Gun_Type_AC:
  3279. gunType[gun_index] = GUN_TYPE_AC;
  3280. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3281. break;
  3282. default:
  3283. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3284. break;
  3285. }
  3286. }
  3287. }
  3288. }
  3289. else
  3290. {
  3291. DEBUG_ERROR("Model name parsing fail.\n");
  3292. result = FAIL;
  3293. }
  3294. if(result != PASS)sleep(5);
  3295. return result;
  3296. }
  3297. void checkRemoteStart(uint8_t connectorIdInt)
  3298. {
  3299. uint8_t tempIndex;
  3300. int result = PASS;
  3301. char cmdBuf[512];
  3302. //check Transaction active
  3303. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3304. {
  3305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3306. {
  3307. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3308. }
  3309. else
  3310. {
  3311. tempIndex = connectorIdInt -1;
  3312. }
  3313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3314. {
  3315. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3316. {
  3317. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3318. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3319. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3320. {
  3321. //Reserved
  3322. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3323. }
  3324. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3325. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3326. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3327. {
  3328. //Reserved
  3329. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3330. result = FAIL;
  3331. goto end;
  3332. }
  3333. else
  3334. {
  3335. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3336. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3339. {
  3340. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3341. result = FAIL;
  3342. goto end;
  3343. }
  3344. }//END FOR ELSE
  3345. }
  3346. }// END FOR CHAdeMO_QUANTITY
  3347. }
  3348. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3349. {
  3350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3351. {
  3352. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3353. }
  3354. else
  3355. {
  3356. tempIndex = connectorIdInt -1;
  3357. }
  3358. for (int index = 0; index < CCS_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3361. {
  3362. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3363. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3364. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3365. {
  3366. //Reserved
  3367. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3368. }
  3369. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3370. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3371. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3372. {
  3373. //Reserved
  3374. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3375. result = FAIL;
  3376. goto end;
  3377. }
  3378. else
  3379. {
  3380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3381. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3382. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3384. {
  3385. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3386. result = FAIL;
  3387. goto end;
  3388. }
  3389. }// END FOR ELSE
  3390. }
  3391. }// END FOR CCS_QUANTITY
  3392. }
  3393. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3394. {
  3395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3396. {
  3397. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3398. }
  3399. else
  3400. {
  3401. tempIndex = connectorIdInt -1;
  3402. }
  3403. for (int index = 0; index < GB_QUANTITY; index++)
  3404. {
  3405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3406. {
  3407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3408. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3409. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3410. {
  3411. //Reserved
  3412. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3413. }
  3414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3416. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3417. {
  3418. //Reserved
  3419. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3420. result = FAIL;
  3421. goto end;
  3422. }
  3423. else
  3424. {
  3425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3426. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3429. {
  3430. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3431. result = FAIL;
  3432. goto end;
  3433. }
  3434. }// END FOR ELSE
  3435. }
  3436. } // END FOR GB_QUANTITY
  3437. }
  3438. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3439. {
  3440. tempIndex = connectorIdInt -1;
  3441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3442. {
  3443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3444. {
  3445. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3446. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3447. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3448. {
  3449. //Reserved
  3450. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3451. }
  3452. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3453. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3454. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3455. {
  3456. //Reserved
  3457. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3458. result = FAIL;
  3459. goto end;
  3460. }
  3461. else
  3462. {
  3463. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3464. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3465. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3467. {
  3468. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3469. result = FAIL;
  3470. goto end;
  3471. }
  3472. }// END FOR ELSE
  3473. }
  3474. } // END FOR GB_QUANTITY
  3475. }
  3476. else
  3477. {
  3478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3479. {
  3480. tempIndex = 2;
  3481. }
  3482. else
  3483. {
  3484. tempIndex = connectorIdInt -1;
  3485. }
  3486. for (int index = 0; index < AC_QUANTITY; index++)
  3487. {
  3488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3489. {
  3490. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3492. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3493. {
  3494. //Reserved
  3495. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3496. }
  3497. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3499. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3500. {
  3501. //Reserved
  3502. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3503. result = FAIL;
  3504. goto end;
  3505. }
  3506. else
  3507. {
  3508. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3509. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3510. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3512. {
  3513. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3514. result = FAIL;
  3515. goto end;
  3516. }
  3517. }//END FOR ELSE
  3518. }
  3519. }// END FOR AC_QUANTITY
  3520. }
  3521. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3522. {
  3523. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3524. {
  3525. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3526. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3527. {
  3528. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3529. system(cmdBuf);
  3530. }
  3531. }
  3532. else
  3533. {
  3534. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3535. result = FAIL;
  3536. }
  3537. }
  3538. end:
  3539. if(result == PASS)
  3540. {
  3541. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3542. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3543. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3544. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3546. }
  3547. }
  3548. void CheckSystemValue(void)
  3549. {
  3550. char filenmae[100]={0};
  3551. char str[100]={0};
  3552. int tempIndex = 0;
  3553. //===============================
  3554. // send Heartbeat
  3555. //===============================
  3556. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3557. {
  3558. //parameter for test
  3559. sendHeartbeatRequest(0);
  3560. //==============================================
  3561. // Reset Waiting Time
  3562. //==============================================
  3563. HeartBeatWithNOResponse += 2;
  3564. }
  3565. //===============================
  3566. // Credit deduct report
  3567. //===============================
  3568. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3569. {
  3570. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo, ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice, ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData);
  3571. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3572. }
  3573. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3574. {
  3575. OCPP_query_deduct_info();
  3576. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3577. }
  3578. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3579. {
  3580. // ClockAlign MeterValue
  3581. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3582. {
  3583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3584. {
  3585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3586. {
  3587. tempIndex = ((gun_index==2) ? 1: 0);
  3588. }
  3589. else
  3590. {
  3591. tempIndex = gun_index;
  3592. }
  3593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3594. {
  3595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3596. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. reqClockAlignMeter[gun_index] = 1;
  3599. }
  3600. }// End for CHAdeMO
  3601. }
  3602. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3603. {
  3604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3605. {
  3606. tempIndex = ((gun_index==2) ? 1: 0);
  3607. }
  3608. else
  3609. {
  3610. tempIndex = gun_index;
  3611. }
  3612. for (int index = 0; index < CCS_QUANTITY; index++)
  3613. {
  3614. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3615. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3616. {
  3617. reqClockAlignMeter[gun_index] = 1;
  3618. }
  3619. } // End for CCS
  3620. }
  3621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3624. {
  3625. tempIndex = ((gun_index==2) ? 1: 0);
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < GB_QUANTITY; index++)
  3632. {
  3633. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3634. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3635. {
  3636. reqClockAlignMeter[gun_index] = 1;
  3637. }
  3638. }// End for GB
  3639. }
  3640. else if(gunType[gun_index] == GUN_TYPE_DO)
  3641. {
  3642. tempIndex = gun_index;
  3643. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3644. {
  3645. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3646. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3647. {
  3648. reqClockAlignMeter[gun_index] = 1;
  3649. }
  3650. }
  3651. }
  3652. else
  3653. {
  3654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3655. {
  3656. tempIndex = 2;
  3657. }
  3658. else
  3659. {
  3660. tempIndex = gun_index;
  3661. }
  3662. for (int index = 0; index < AC_QUANTITY; index++)
  3663. {
  3664. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3665. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3666. {
  3667. reqClockAlignMeter[gun_index] = 1;
  3668. }
  3669. }//End for AC
  3670. }
  3671. }
  3672. }
  3673. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3674. {
  3675. //==========================================
  3676. // Check remote start without connector id
  3677. //==========================================
  3678. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3679. {
  3680. int connectorIdInt = -1;
  3681. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3682. {
  3683. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3684. {
  3685. connectorIdInt = (gun_index+1);
  3686. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3687. checkRemoteStart(connectorIdInt);
  3688. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3689. break;
  3690. }
  3691. }
  3692. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3693. {
  3694. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3695. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3696. }
  3697. }
  3698. //==========================================
  3699. // csu trigger DataTransferReq
  3700. //==========================================
  3701. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3702. {
  3703. sendDataTransferRequest(gun_index);
  3704. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3705. }
  3706. //===============================
  3707. // CSU Trigger Authorize Request
  3708. //===============================
  3709. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3710. {
  3711. sendAuthorizeRequest(0);
  3712. authorizeRetryTimes = authorizeRetryTimes + 1;
  3713. if(authorizeRetryTimes < 3)
  3714. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3715. }
  3716. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3717. {
  3718. authorizeRetryTimes = 0;
  3719. SetOcppConnStatus(FALSE);
  3720. server_sign = FALSE;
  3721. }
  3722. 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))
  3723. {
  3724. sendAuthorizeRequest(0);
  3725. }
  3726. //==============================================
  3727. // Charger start transaction
  3728. //==============================================
  3729. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3730. {
  3731. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3732. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3733. sendStartTransactionRequest(gun_index);
  3734. refreshStartTimer(&clientTime.StartTransaction);
  3735. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3736. //storeTempStopTransaction(gun_index);
  3737. }
  3738. //==============================================
  3739. // Charger stop transaction
  3740. //==============================================
  3741. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3742. {
  3743. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3744. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3745. sendStopTransactionRequest(gun_index);
  3746. refreshStartTimer(&clientTime.StopTransaction);
  3747. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3748. }
  3749. //==============================================
  3750. // Charger status report
  3751. //==============================================
  3752. //--- Check Mode Change ---//
  3753. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3757. {
  3758. tempIndex = ((gun_index==2) ? 1: 0);
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3767. {
  3768. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3769. {
  3770. // Sent unplug message for California pricing logic
  3771. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3772. {
  3773. uint8_t ts[20];
  3774. getNowDatetime(ts);
  3775. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3776. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3777. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3778. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3779. }
  3780. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3781. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3782. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3783. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3784. {
  3785. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3786. if((access(filenmae,F_OK))!=-1)
  3787. {
  3788. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3789. sprintf(str,"rm -f %s",filenmae);
  3790. system(str);
  3791. }
  3792. }
  3793. }
  3794. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3795. #if 1 // for TempStopTransaction
  3796. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3797. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3798. {
  3799. checkTempStopTransaction(gun_index);
  3800. }
  3801. #endif
  3802. }
  3803. }
  3804. }
  3805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3806. {
  3807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3808. {
  3809. tempIndex = ((gun_index==2) ? 1: 0);
  3810. }
  3811. else
  3812. {
  3813. tempIndex = gun_index;
  3814. }
  3815. for (int index = 0; index < CCS_QUANTITY; index++)
  3816. {
  3817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3818. {
  3819. 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]*/ )
  3820. {
  3821. // Sent unplug message for California pricing logic
  3822. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3823. {
  3824. uint8_t ts[20];
  3825. getNowDatetime(ts);
  3826. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3827. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3828. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3829. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3830. }
  3831. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3832. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3834. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3835. {
  3836. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3837. if((access(filenmae,F_OK))!=-1)
  3838. {
  3839. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3840. sprintf(str,"rm -f %s",filenmae);
  3841. system(str);
  3842. }
  3843. }
  3844. }
  3845. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3846. #if 1 // for TempStopTransaction
  3847. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3848. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3849. {
  3850. checkTempStopTransaction(gun_index);
  3851. }
  3852. #endif
  3853. }
  3854. }
  3855. }
  3856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3857. {
  3858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3859. {
  3860. tempIndex = ((gun_index==2) ? 1: 0);
  3861. }
  3862. else
  3863. {
  3864. tempIndex = gun_index;
  3865. }
  3866. for (int index = 0; index < GB_QUANTITY; index++)
  3867. {
  3868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3869. {
  3870. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3871. {
  3872. // Sent unplug message for California pricing logic
  3873. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3874. {
  3875. uint8_t ts[20];
  3876. getNowDatetime(ts);
  3877. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3878. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3879. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3880. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3881. }
  3882. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3883. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3884. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3885. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3886. {
  3887. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3888. if((access(filenmae,F_OK))!=-1)
  3889. {
  3890. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3891. sprintf(str,"rm -f %s",filenmae);
  3892. system(str);
  3893. }
  3894. }
  3895. }
  3896. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3897. #if 1 // for TempStopTransaction
  3898. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3899. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3900. {
  3901. checkTempStopTransaction(gun_index);
  3902. }
  3903. #endif
  3904. }
  3905. }
  3906. }
  3907. else if(gunType[gun_index] == GUN_TYPE_DO)
  3908. {
  3909. tempIndex = gun_index;
  3910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3911. {
  3912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3913. {
  3914. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3915. {
  3916. // Sent unplug message for California pricing logic
  3917. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3918. {
  3919. uint8_t ts[20];
  3920. getNowDatetime(ts);
  3921. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3922. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3923. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3924. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3925. }
  3926. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3927. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3928. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3929. 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
  3930. {
  3931. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3932. if((access(filenmae,F_OK))!=-1)
  3933. {
  3934. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3935. sprintf(str,"rm -f %s",filenmae);
  3936. system(str);
  3937. }
  3938. }
  3939. }
  3940. 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);
  3941. #if 1 // for TempStopTransaction
  3942. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3943. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3944. {
  3945. checkTempStopTransaction(gun_index);
  3946. }
  3947. #endif
  3948. }
  3949. }
  3950. }
  3951. else
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3954. {
  3955. tempIndex = 2;
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < AC_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3964. {
  3965. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3966. {
  3967. // Sent unplug message for California pricing logic
  3968. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3969. {
  3970. uint8_t ts[20];
  3971. getNowDatetime(ts);
  3972. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3973. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3974. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3975. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3976. }
  3977. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3978. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3979. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3980. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3981. {
  3982. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3983. if((access(filenmae,F_OK))!=-1)
  3984. {
  3985. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3986. sprintf(str,"rm -f %s",filenmae);
  3987. system(str);
  3988. }
  3989. }
  3990. }
  3991. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3992. #if 1 // for TempStopTransaction
  3993. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3994. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3995. {
  3996. checkTempStopTransaction(gun_index);
  3997. }
  3998. #endif
  3999. }
  4000. }// END
  4001. }
  4002. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4003. (
  4004. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4005. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4006. )
  4007. )
  4008. {
  4009. if(SystemInitial > 0)
  4010. SystemInitial -= 1;
  4011. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4012. sendStatusNotificationRequest(gun_index);
  4013. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4014. }
  4015. //==============================================
  4016. // CSU Trigger Smart Charging Profilw
  4017. //==============================================
  4018. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4019. {
  4020. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4021. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4022. }
  4023. //==============================================
  4024. // Meter report
  4025. //==============================================
  4026. // Trigger MeterValue
  4027. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4028. {
  4029. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4030. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4031. }
  4032. // Clock-aligned Meter value
  4033. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4034. {
  4035. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4036. reqClockAlignMeter[gun_index] = 0;
  4037. }
  4038. // Sample period MeterValue
  4039. 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))))
  4040. {
  4041. //check Transaction active
  4042. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4043. {
  4044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4045. {
  4046. tempIndex = ((gun_index==2) ? 1: 0);
  4047. }
  4048. else
  4049. {
  4050. tempIndex = gun_index;
  4051. }
  4052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4053. {
  4054. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4055. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4056. {
  4057. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4058. {
  4059. reqSampleMeter[gun_index] = 1;
  4060. }
  4061. }
  4062. }// End for CHAdeMO
  4063. }
  4064. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4067. {
  4068. tempIndex = ((gun_index==2) ? 1: 0);
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < CCS_QUANTITY; index++)
  4075. {
  4076. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4077. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4078. {
  4079. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4080. {
  4081. reqSampleMeter[gun_index] = 1;
  4082. }
  4083. }
  4084. } // End for CCS
  4085. }
  4086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4087. {
  4088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4089. {
  4090. tempIndex = ((gun_index==2) ? 1: 0);
  4091. }
  4092. else
  4093. {
  4094. tempIndex = gun_index;
  4095. }
  4096. for (int index = 0; index < GB_QUANTITY; index++)
  4097. {
  4098. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4099. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4100. {
  4101. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4102. {
  4103. reqSampleMeter[gun_index] = 1;
  4104. }
  4105. }
  4106. }// End for GB
  4107. }
  4108. else if(gunType[gun_index] == GUN_TYPE_DO)
  4109. {
  4110. tempIndex = gun_index;
  4111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4112. {
  4113. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4114. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4117. {
  4118. reqSampleMeter[gun_index] = 1;
  4119. }
  4120. }
  4121. }
  4122. }
  4123. else
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4126. {
  4127. tempIndex = 2;
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < AC_QUANTITY; index++)
  4134. {
  4135. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4136. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4137. {
  4138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4139. {
  4140. reqSampleMeter[gun_index] = 1;
  4141. }
  4142. }
  4143. }//End for AC
  4144. }
  4145. if(reqSampleMeter[gun_index] == 1)
  4146. {
  4147. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4148. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4149. //storeTempStopTransaction(gun_index);
  4150. reqSampleMeter[gun_index] = 0;
  4151. }
  4152. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4153. }
  4154. //==============================================
  4155. // Check Connector reserved
  4156. //==============================================
  4157. //===============================
  4158. // Check if Reserve is expired
  4159. //===============================
  4160. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4161. {
  4162. double diff_t;
  4163. struct tm tp;
  4164. // current time
  4165. time_t t = time(NULL);
  4166. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4167. tp.tm_isdst = -1;
  4168. time_t utc = mktime(&tp);
  4169. diff_t = difftime(utc, t);
  4170. if(diff_t <= 0)
  4171. {
  4172. DEBUG_INFO("reserve expired.\n");
  4173. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4174. }
  4175. }//END OF Check if Reserve is expired
  4176. //==========================================
  4177. // csu trigger FirmwareStatusNotificationReq
  4178. //==========================================
  4179. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4180. {
  4181. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4182. }
  4183. //==========================================
  4184. // csu trigger DiagnosticsStatusNotificationReq
  4185. //==========================================
  4186. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4187. {
  4188. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4189. }
  4190. //==========================================
  4191. // csu trigger CancelReservationConf
  4192. //==========================================
  4193. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4194. {
  4195. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4196. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4197. }
  4198. //==========================================
  4199. // csu trigger ChangeAvailabilityConf
  4200. //==========================================
  4201. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4202. {
  4203. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4204. }
  4205. //==========================================
  4206. // csu trigger UnlockConnectorConf
  4207. //==========================================
  4208. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4209. {
  4210. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4211. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4212. }
  4213. //==========================================
  4214. // csu trigger ReserveNowConf
  4215. //==========================================
  4216. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4217. {
  4218. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4219. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4220. }
  4221. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4222. {
  4223. sendSignCertificateRequest();
  4224. }
  4225. }
  4226. }
  4227. //==========================================
  4228. // send request routine
  4229. //==========================================
  4230. int sendAuthorizeRequest(int gun_index)
  4231. {
  4232. mtrace();
  4233. int result = FAIL;
  4234. char message[100]={0};
  4235. char guid[37];
  4236. char tempdata[65]={0};
  4237. DEBUG_INFO("sendAuthorizeRequest...\n");
  4238. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4239. //Local Authorize
  4240. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4241. {
  4242. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4243. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4244. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4245. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4246. result = PASS;
  4247. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4248. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4249. authorizeRetryTimes = 0;
  4250. return result;
  4251. }
  4252. 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))||
  4253. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4254. {
  4255. // Query from cache
  4256. DEBUG_INFO("Authorize from cache.\n");
  4257. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4258. // Query from list
  4259. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4260. {
  4261. DEBUG_INFO("Authorize from list.\n");
  4262. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4263. }
  4264. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4265. {
  4266. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4267. {
  4268. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4269. }
  4270. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4271. {
  4272. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4273. }
  4274. if(!GetOcppConnStatus())
  4275. {
  4276. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4277. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4278. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4279. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4280. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4281. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4282. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4283. authorizeRetryTimes = 0;
  4284. return result;
  4285. }
  4286. }
  4287. else
  4288. {
  4289. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4291. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4292. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4293. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4294. else
  4295. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4296. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4297. result = PASS;
  4298. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4299. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4300. authorizeRetryTimes = 0;
  4301. return result;
  4302. }
  4303. }
  4304. //initialize struct Authorize
  4305. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4306. //get data from shared memory
  4307. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4308. random_uuid(guid);
  4309. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4310. LWS_Send(message);
  4311. sprintf(tempdata, "Authorize,%d", gun_index);
  4312. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4313. {
  4314. result = PASS;
  4315. DEBUG_INFO("Authorize mapItem pass\n");
  4316. }
  4317. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4318. return result;
  4319. }
  4320. int sendBootNotificationRequest(void)
  4321. {
  4322. mtrace();
  4323. int result = FAIL;
  4324. char message[500]={0}, payload[700]={0};
  4325. char guid[37]={0};
  4326. char tempdata[65]={0};
  4327. // Fill BootNotification fields
  4328. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4329. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4330. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4331. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4332. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4333. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4334. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4335. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4336. ShmOCPP16DataPH->ChargeBoxId
  4337. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4338. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4339. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4340. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4341. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4342. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4343. random_uuid(guid);
  4344. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4345. LWS_Send(message);
  4346. sprintf(tempdata, "BootNotification,0");
  4347. 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*/)
  4348. {
  4349. result = PASS;
  4350. }
  4351. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4352. strcpy(queuedata,message);
  4353. return result;
  4354. }
  4355. int sendDataTransferRequest(int gun_index)
  4356. {
  4357. mtrace();
  4358. char message[1000]={0};
  4359. char guid[37]={0};
  4360. char tempdata[65]={0};
  4361. int result = FAIL;
  4362. random_uuid(guid);
  4363. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4364. MESSAGE_TYPE_CALL,
  4365. guid,
  4366. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4367. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4368. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4369. LWS_Send(message);
  4370. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4371. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4372. {
  4373. result = PASS;
  4374. DEBUG_INFO("DataTransfer mapItem pass\n");
  4375. }
  4376. return result;
  4377. }
  4378. int sendDiagnosticsStatusNotificationRequest(char *status)
  4379. {
  4380. mtrace();
  4381. int result = FAIL;
  4382. char message[110]={0};
  4383. char guid[37]={0};
  4384. char tempdata[65]={0};
  4385. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4386. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4387. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4388. random_uuid(guid);
  4389. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4390. LWS_SendNow(message);
  4391. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4392. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4393. {
  4394. result = PASS;
  4395. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4396. }
  4397. //#ifdef SystemLogMessage
  4398. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4399. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4400. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4401. //#endif
  4402. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4403. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4404. //record status
  4405. if(strcmp(status,"Idle")==0)
  4406. {
  4407. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4408. }
  4409. else if(strcmp(status,"Uploaded")==0)
  4410. {
  4411. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4412. }
  4413. else if(strcmp(status,"UploadFailed")==0)
  4414. {
  4415. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4416. }
  4417. else if(strcmp(status,"Uploading")==0)
  4418. {
  4419. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4420. }
  4421. return result;
  4422. }
  4423. int sendFirmwareStatusNotificationRequest(char *status)
  4424. {
  4425. mtrace();
  4426. int result = FAIL;
  4427. char message[110]={0};
  4428. char guid[37]={0};
  4429. char tempdata[65]={0};
  4430. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4431. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4432. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4433. random_uuid(guid);
  4434. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4435. LWS_SendNow(message);
  4436. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4437. 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*/)
  4438. {
  4439. result = PASS;
  4440. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4441. }
  4442. //#ifdef SystemLogMessage
  4443. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4444. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4445. //#endif
  4446. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4447. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4448. //record status
  4449. if(strcmp(status,"Downloaded")==0)
  4450. {
  4451. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4452. }
  4453. else if(strcmp(status,"DownloadFailed")==0)
  4454. {
  4455. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4456. }
  4457. else if(strcmp(status,"Downloading")==0)
  4458. {
  4459. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4460. }
  4461. else if(strcmp(status,"Idle")==0)
  4462. {
  4463. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4464. }
  4465. else if(strcmp(status,"InstallationFailed")==0)
  4466. {
  4467. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4468. }
  4469. else if(strcmp(status,"Installing")==0)
  4470. {
  4471. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4472. }
  4473. else if(strcmp(status,"Installed")==0)
  4474. {
  4475. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4476. }
  4477. return result;
  4478. }
  4479. int sendHeartbeatRequest(int gun_index)
  4480. {
  4481. mtrace();
  4482. int result = FAIL;
  4483. char message[80]={0};
  4484. char guid[37]={0};
  4485. char tempdata[65]={0};
  4486. random_uuid(guid);
  4487. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4488. , MESSAGE_TYPE_CALL
  4489. , guid );
  4490. LWS_Send(message);
  4491. sprintf(tempdata, "Heartbeat,%d", 0);
  4492. 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*/)
  4493. {
  4494. result = PASS;
  4495. }
  4496. return result;
  4497. }
  4498. int sendStartTransactionRequest(int gun_index)
  4499. {
  4500. mtrace();
  4501. int result = FAIL;
  4502. char message[250]={0};
  4503. char guid[37]={0};
  4504. struct timeval tmnow;
  4505. struct tm *tm;
  4506. char buf[28];//, usec_buf[6];
  4507. char tempdata[65]={0};
  4508. int tempIndex = 0;
  4509. DEBUG_INFO("sendStartTransactionRequest...\n");
  4510. gettimeofday(&tmnow, NULL);
  4511. time_t t;
  4512. t = time(NULL);
  4513. /*UTC time and date*/
  4514. tm = gmtime(&t);
  4515. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4516. #if 0 // remove temporally
  4517. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4518. strcat(buf,".");
  4519. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4520. strcat(buf,usec_buf);
  4521. #endif
  4522. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4523. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4524. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4525. // clear StartTransaction Response
  4526. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4527. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4528. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4529. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4530. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4531. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4532. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4535. {
  4536. tempIndex = ((gun_index==2) ? 1: 0);
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4545. {
  4546. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4547. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4548. }
  4549. }
  4550. }
  4551. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4552. {
  4553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4554. {
  4555. tempIndex = ((gun_index==2) ? 1: 0);
  4556. }
  4557. else
  4558. {
  4559. tempIndex = gun_index;
  4560. }
  4561. for (int index = 0; index < CCS_QUANTITY; index++)
  4562. {
  4563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4564. {
  4565. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4566. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4567. }
  4568. }
  4569. }
  4570. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4573. {
  4574. tempIndex = ((gun_index==2) ? 1: 0);
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < GB_QUANTITY; index++)
  4581. {
  4582. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4583. {
  4584. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4585. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4586. }
  4587. }
  4588. }
  4589. else if(gunType[gun_index] == GUN_TYPE_DO)
  4590. {
  4591. tempIndex = gun_index;
  4592. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4595. {
  4596. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4597. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4598. }
  4599. }
  4600. }
  4601. else
  4602. {
  4603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4604. {
  4605. tempIndex = 2;
  4606. }
  4607. else
  4608. {
  4609. tempIndex = gun_index;
  4610. }
  4611. for (int index = 0; index < AC_QUANTITY; index++)
  4612. {
  4613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4614. {
  4615. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4616. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4617. }
  4618. }
  4619. }
  4620. random_uuid(guid);
  4621. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4622. {
  4623. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4624. , gun_index +1
  4625. , MESSAGE_TYPE_CALL
  4626. , guid
  4627. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4628. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4629. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4630. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4631. }
  4632. else
  4633. {
  4634. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4635. , gun_index +1
  4636. , MESSAGE_TYPE_CALL
  4637. , guid
  4638. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4639. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4640. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4641. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4642. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4643. }
  4644. #if 1
  4645. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4646. 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*/)
  4647. {
  4648. result = PASS;
  4649. }
  4650. #endif
  4651. strcpy(queuedata, message);
  4652. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4653. OCPP_insert_transaction_msg(YES, queuedata);
  4654. return result;
  4655. }
  4656. int sendStatusNotificationRequest(int gun_index)
  4657. {
  4658. mtrace();
  4659. int result = FAIL;
  4660. char message[600]={0};
  4661. char guid[37];
  4662. int currentStatus = 0;
  4663. struct timeval tmnow;
  4664. struct tm *tm;
  4665. char buf[28];//, usec_buf[6];
  4666. char tempdata[65]={0};
  4667. int tempIndex = 0;
  4668. uint8_t isStateChanged = TRUE;
  4669. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4670. gettimeofday(&tmnow, NULL);
  4671. time_t t;
  4672. t = time(NULL);
  4673. /*UTC time and date*/
  4674. tm = gmtime(&t);
  4675. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4676. #if 0 // remove temporally
  4677. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4678. strcat(buf,".");
  4679. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4680. strcat(buf,usec_buf);
  4681. #endif
  4682. //printf("%s",buf);
  4683. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4684. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4685. // it's option
  4686. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4687. /*
  4688. enum _SYSTEM_STATUS
  4689. {
  4690. S_BOOTING = 0,
  4691. S_IDLE, = 1
  4692. S_AUTHORIZING, =2
  4693. S_REASSIGN_CHECK, =3
  4694. S_REASSIGN, =4
  4695. S_PRECHARGE, =5
  4696. S_PREPARING_FOR_EV, =6
  4697. S_PREPARING_FOR_EVSE, =7
  4698. S_CHARGING, =8
  4699. S_TERMINATING, =9
  4700. S_COMPLETE, =10
  4701. S_ALARM, =11
  4702. S_FAULT =12
  4703. }
  4704. */
  4705. //check Transaction active
  4706. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4707. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4708. {
  4709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4710. {
  4711. tempIndex = ((gun_index==2) ? 1: 0);
  4712. }
  4713. else
  4714. {
  4715. tempIndex = gun_index;
  4716. }
  4717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4718. {
  4719. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4720. {
  4721. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4722. {
  4723. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4724. {
  4725. currentStatus = Preparing; //OCPP Status: Preparing
  4726. }
  4727. else
  4728. {
  4729. currentStatus = Available; //OCPP Status: Available
  4730. }
  4731. }
  4732. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4733. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4734. ) //S_PRECHARGE
  4735. {
  4736. currentStatus = Preparing; //OCPP Status: Preparing
  4737. }
  4738. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4739. {
  4740. currentStatus = Charging; //OCPP Status: Charging
  4741. }
  4742. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4743. {
  4744. currentStatus = Finishing; //OCPP Status: Finishing
  4745. }
  4746. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4747. {
  4748. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4749. }
  4750. 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
  4751. {
  4752. currentStatus = Unavailable; //OCPP Status: Unavailable
  4753. }
  4754. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4755. {
  4756. currentStatus = Faulted; //OCPP Status: Faulted
  4757. }
  4758. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4759. {
  4760. currentStatus = Reserved; //OCPP Status: Reserved
  4761. }
  4762. } //end of the same index
  4763. }//end of for CHAdeMO_QUANTITY
  4764. }
  4765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4766. {
  4767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4768. {
  4769. tempIndex = ((gun_index==2) ? 1: 0);
  4770. }
  4771. else
  4772. {
  4773. tempIndex = gun_index;
  4774. }
  4775. for (int index = 0; index < CCS_QUANTITY; index++)
  4776. {
  4777. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4778. {
  4779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4780. {
  4781. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4782. {
  4783. currentStatus = Preparing; //OCPP Status: Preparing
  4784. }
  4785. else
  4786. {
  4787. currentStatus = Available; //OCPP Status: Available
  4788. }
  4789. }
  4790. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4791. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4792. ) //S_PRECHARGE
  4793. {
  4794. currentStatus = Preparing; //OCPP Status: Preparing
  4795. }
  4796. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4797. {
  4798. currentStatus = Charging; //OCPP Status: Charging
  4799. }
  4800. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4801. {
  4802. currentStatus = Finishing; //OCPP Status: Finishing
  4803. }
  4804. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4805. {
  4806. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4807. }
  4808. 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
  4809. {
  4810. currentStatus = Unavailable; //OCPP Status : Unavailable
  4811. }
  4812. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4813. {
  4814. currentStatus = Faulted; //OCPP Status: Faulted
  4815. }
  4816. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4817. {
  4818. currentStatus = Reserved; //OCPP Status: Reserved
  4819. }
  4820. } //end of the same index
  4821. } // end of for CCS_QUANTITY
  4822. }
  4823. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4824. {
  4825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4826. {
  4827. tempIndex = ((gun_index==2) ? 1: 0);
  4828. }
  4829. else
  4830. {
  4831. tempIndex = gun_index;
  4832. }
  4833. for (int index = 0; index < GB_QUANTITY; index++)
  4834. {
  4835. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4836. {
  4837. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4838. {
  4839. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4840. {
  4841. currentStatus = Preparing; //OCPP Status: Preparing
  4842. }
  4843. else
  4844. {
  4845. currentStatus = Available; //OCPP Status: Available
  4846. }
  4847. }
  4848. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4849. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4850. ) //S_PRECHARGE
  4851. {
  4852. currentStatus = Preparing; //OCPP Status: Preparing
  4853. }
  4854. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4855. {
  4856. currentStatus = Charging; //OCPP Status: Charging
  4857. }
  4858. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4859. {
  4860. currentStatus = Finishing; //OCPP Status: Finishing
  4861. }
  4862. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4863. {
  4864. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4865. }
  4866. 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
  4867. {
  4868. currentStatus = Unavailable; //OCPP Status: Unavailable
  4869. }
  4870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4871. {
  4872. currentStatus = Faulted; //OCPP Status: Faulted
  4873. }
  4874. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4875. {
  4876. currentStatus = Reserved; //OCPP Status: Reserved
  4877. }
  4878. } //end of the same index
  4879. } // end of for GB_QUANTITY
  4880. }
  4881. else if(gunType[gun_index] == GUN_TYPE_DO)
  4882. {
  4883. tempIndex = gun_index;
  4884. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4885. {
  4886. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4887. {
  4888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4889. {
  4890. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4891. {
  4892. currentStatus = Preparing; //OCPP Status: Preparing
  4893. }
  4894. else
  4895. {
  4896. currentStatus = Available; //OCPP Status: Available
  4897. }
  4898. }
  4899. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4900. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4901. ) //S_PRECHARGE
  4902. {
  4903. currentStatus = Preparing; //OCPP Status: Preparing
  4904. }
  4905. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4906. {
  4907. currentStatus = Charging; //OCPP Status: Charging
  4908. }
  4909. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4910. {
  4911. currentStatus = Finishing; //OCPP Status: Finishing
  4912. }
  4913. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4914. {
  4915. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4916. }
  4917. 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
  4918. {
  4919. currentStatus = Unavailable; //OCPP Status: Unavailable
  4920. }
  4921. 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
  4922. {
  4923. currentStatus = Faulted; //OCPP Status: Faulted
  4924. }
  4925. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4926. {
  4927. currentStatus = Reserved; //OCPP Status: Reserved
  4928. }
  4929. } //end of the same index
  4930. }
  4931. }
  4932. else
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4935. {
  4936. tempIndex = 2;
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < AC_QUANTITY; index++)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4945. {
  4946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4947. {
  4948. 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))
  4949. {
  4950. currentStatus = Preparing; //OCPP Status: Preparing
  4951. }
  4952. else
  4953. {
  4954. currentStatus = Available; //OCPP Status: Available
  4955. }
  4956. }
  4957. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4958. {
  4959. currentStatus = Preparing; //OCPP Status: Preparing
  4960. }
  4961. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4962. {
  4963. currentStatus = Charging; //OCPP Status: Charging
  4964. }
  4965. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4966. {
  4967. currentStatus = Finishing; //OCPP Status: Finishing
  4968. }
  4969. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4970. {
  4971. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4972. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4973. else
  4974. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4975. }
  4976. 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
  4977. {
  4978. currentStatus = Unavailable; //OCPP Status: Unavailable
  4979. }
  4980. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4981. {
  4982. currentStatus = Faulted; //OCPP Status: Faulted
  4983. }
  4984. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4985. {
  4986. currentStatus = Reserved; //OCPP Status: Reserved
  4987. }
  4988. }//end of the same index
  4989. }//end of for AC_QUANTITY
  4990. }
  4991. //it's option
  4992. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4993. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  4994. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  4995. {
  4996. isStateChanged = FALSE;
  4997. }
  4998. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4999. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5000. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5001. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5002. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5003. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5004. random_uuid(guid);
  5005. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5006. , MESSAGE_TYPE_CALL
  5007. , guid
  5008. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5009. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5010. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5011. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5012. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5013. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5014. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5015. if((server_sign == TRUE) && isStateChanged)
  5016. {
  5017. LWS_Send(message);
  5018. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5019. 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*/)
  5020. {
  5021. //DEBUG_ERROR("statusNotification mapitem pass");
  5022. result = PASS;
  5023. }
  5024. }
  5025. else
  5026. {
  5027. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5028. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5029. result = PASS;
  5030. }
  5031. return result;
  5032. }
  5033. int sendStopTransactionRequest(int gun_index)
  5034. {
  5035. mtrace();
  5036. int result = FAIL;
  5037. //char message[1500]={0};
  5038. char guid[37]={0};
  5039. char tempdata[65]={0};
  5040. int tempIndex = 0;
  5041. char TempStopTransaction[256];
  5042. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5043. //int idx_sample=0;
  5044. DEBUG_INFO("sendStopTransactionRequest \n");
  5045. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5046. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5047. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5048. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5049. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5052. {
  5053. tempIndex = ((gun_index==2) ? 1: 0);
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5062. {
  5063. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5064. }
  5065. }// END OF CHAdeMO_QUANTITY
  5066. }
  5067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5068. {
  5069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5070. {
  5071. tempIndex = ((gun_index==2) ? 1: 0);
  5072. }
  5073. else
  5074. {
  5075. tempIndex = gun_index;
  5076. }
  5077. for (int index = 0; index < CCS_QUANTITY; index++)
  5078. {
  5079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5080. {
  5081. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5082. }
  5083. }// END OF CCS_QUANTITY
  5084. }
  5085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5086. {
  5087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5088. {
  5089. tempIndex = ((gun_index==2) ? 1: 0);
  5090. }
  5091. else
  5092. {
  5093. tempIndex = gun_index;
  5094. }
  5095. for (int index = 0; index < GB_QUANTITY; index++)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5098. {
  5099. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5100. }
  5101. }// END OF GB_QUANTITY
  5102. }
  5103. else if(gunType[gun_index] == GUN_TYPE_DO)
  5104. {
  5105. tempIndex = gun_index;
  5106. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5107. {
  5108. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5109. {
  5110. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5111. }
  5112. }// END OF GB_QUANTITY
  5113. }
  5114. else
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5117. {
  5118. tempIndex = 2;
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < AC_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5127. {
  5128. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5129. }
  5130. }// END OF AC_QUANTITY
  5131. }
  5132. //====================================== Stop Transaction Time =====================================================
  5133. struct timeval tmnow;
  5134. struct tm *tm;
  5135. char buf[28];//, usec_buf[6];
  5136. gettimeofday(&tmnow, NULL);
  5137. time_t t;
  5138. t = time(NULL);
  5139. /*UTC time and date*/
  5140. tm = gmtime(&t);
  5141. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5143. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5144. random_uuid(guid);
  5145. /***********************************transactionData******************************************************/
  5146. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5148. //=================================
  5149. // Transaction_Begin
  5150. //=================================
  5151. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5152. {
  5153. //============================================ Energy.Active.Import.Interval ================================
  5154. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5157. 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*/]);
  5158. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5159. 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))
  5160. {
  5161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5162. }
  5163. else
  5164. {
  5165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5166. }
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5169. }
  5170. //=================================
  5171. // Transaction_End
  5172. //=================================
  5173. // ================================= Current.Import L1 ===============================================
  5174. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5175. {
  5176. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5177. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5192. }
  5193. }// End of for CHAdeMO_QUANTITY
  5194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < CCS_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5209. {
  5210. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5211. }
  5212. }// End of for CCS_QUANTITY
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5216. {
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5218. {
  5219. tempIndex = ((gun_index==2) ? 1: 0);
  5220. }
  5221. else
  5222. {
  5223. tempIndex = gun_index;
  5224. }
  5225. for (int index = 0; index < GB_QUANTITY; index++)
  5226. {
  5227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5228. {
  5229. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5230. }
  5231. }// End of for GB_QUANTITY
  5232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_DO)
  5235. {
  5236. tempIndex = gun_index;
  5237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5238. {
  5239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5240. {
  5241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5242. }
  5243. }
  5244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5245. }
  5246. else
  5247. {
  5248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5249. {
  5250. tempIndex = 2;
  5251. }
  5252. else
  5253. {
  5254. tempIndex = gun_index;
  5255. }
  5256. for (int index = 0; index < AC_QUANTITY; index++)
  5257. {
  5258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5259. {
  5260. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5261. }
  5262. }// End of for AC_QUANTITY
  5263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5264. }
  5265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5270. }
  5271. // ================================= Energy.Active.Import.Interval ==============================================
  5272. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5273. {
  5274. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5275. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5278. {
  5279. tempIndex = ((gun_index==2) ? 1: 0);
  5280. }
  5281. else
  5282. {
  5283. tempIndex = gun_index;
  5284. }
  5285. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5290. }
  5291. }// END OF CHAdeMO_QUANTITY
  5292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5293. }
  5294. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. for (int index = 0; index < CCS_QUANTITY; index++)
  5305. {
  5306. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5307. {
  5308. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5309. }
  5310. }// END OF CCS_QUANTITY
  5311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5314. {
  5315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5316. {
  5317. tempIndex = ((gun_index==2) ? 1: 0);
  5318. }
  5319. else
  5320. {
  5321. tempIndex = gun_index;
  5322. }
  5323. for (int index = 0; index < GB_QUANTITY; index++)
  5324. {
  5325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5326. {
  5327. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5328. }
  5329. }// END OF GB_QUANTITY
  5330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5331. }
  5332. else if(gunType[gun_index] == GUN_TYPE_DO)
  5333. {
  5334. tempIndex = gun_index;
  5335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5340. }
  5341. }
  5342. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5343. }
  5344. else
  5345. {
  5346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5347. {
  5348. tempIndex = 2;
  5349. }
  5350. else
  5351. {
  5352. tempIndex = gun_index;
  5353. }
  5354. for (int index = 0; index < AC_QUANTITY; index++)
  5355. {
  5356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5357. {
  5358. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5359. }
  5360. }// END OF AC_QUANTITY
  5361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5362. }
  5363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5368. }
  5369. //=================================== Power.Active.Import ==================================================
  5370. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5371. {
  5372. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5373. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5376. {
  5377. tempIndex = ((gun_index==2) ? 1: 0);
  5378. }
  5379. else
  5380. {
  5381. tempIndex = gun_index;
  5382. }
  5383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5388. }
  5389. } // End for CHAdeMO_QUANTITY
  5390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5393. {
  5394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5395. {
  5396. tempIndex = ((gun_index==2) ? 1: 0);
  5397. }
  5398. else
  5399. {
  5400. tempIndex = gun_index;
  5401. }
  5402. for (int index = 0; index < CCS_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5407. }
  5408. } // END for CCS_QUANTITY
  5409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5412. {
  5413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5414. {
  5415. tempIndex = ((gun_index==2) ? 1: 0);
  5416. }
  5417. else
  5418. {
  5419. tempIndex = gun_index;
  5420. }
  5421. for (int index = 0; index < GB_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5426. }
  5427. }// END for GB_QUANTITY
  5428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5429. }
  5430. else if(gunType[gun_index] == GUN_TYPE_DO)
  5431. {
  5432. tempIndex = gun_index;
  5433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5436. {
  5437. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5438. }
  5439. }
  5440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5441. }
  5442. else
  5443. {
  5444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5445. {
  5446. tempIndex = 2;
  5447. }
  5448. else
  5449. {
  5450. tempIndex = gun_index;
  5451. }
  5452. for (int index = 0; index < AC_QUANTITY; index++)
  5453. {
  5454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5455. {
  5456. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5457. }
  5458. } // END for AC_QUANTITY
  5459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5460. }
  5461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5466. }
  5467. //============================ Voltage L1 ====================================
  5468. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5469. {
  5470. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5471. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5474. {
  5475. tempIndex = ((gun_index==2) ? 1: 0);
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5486. }
  5487. } // END OF FOR CHAdeMO_QUANTITY
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5489. }
  5490. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5493. {
  5494. tempIndex = ((gun_index==2) ? 1: 0);
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < CCS_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5503. {
  5504. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5505. }
  5506. } // END OF FOR CCS_QUANTITY
  5507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5508. }
  5509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5510. {
  5511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5512. {
  5513. tempIndex = ((gun_index==2) ? 1: 0);
  5514. }
  5515. else
  5516. {
  5517. tempIndex = gun_index;
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5524. }
  5525. } // END OF FOR GB_QUANTITY
  5526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5527. }
  5528. else if(gunType[gun_index] == GUN_TYPE_DO)
  5529. {
  5530. tempIndex = gun_index;
  5531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5532. {
  5533. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5534. {
  5535. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5536. }
  5537. }
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5539. }
  5540. else
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5543. {
  5544. tempIndex = 2;
  5545. }
  5546. else
  5547. {
  5548. tempIndex = gun_index;
  5549. }
  5550. for (int index = 0; index < AC_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5553. {
  5554. 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
  5555. }
  5556. } // END OF FOR AC_QUANTITY
  5557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5558. }
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5564. }
  5565. //====================== End SoC ================================
  5566. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5567. {
  5568. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5569. 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))
  5570. {
  5571. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5572. {
  5573. tempIndex = ((gun_index==2) ? 1: 0);
  5574. }
  5575. else
  5576. {
  5577. tempIndex = gun_index;
  5578. }
  5579. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5580. {
  5581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5582. {
  5583. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5584. {
  5585. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5586. }
  5587. }
  5588. }
  5589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5590. {
  5591. for (int index = 0; index < CCS_QUANTITY; index++)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5594. {
  5595. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5596. }
  5597. }
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5600. {
  5601. for (int index = 0; index < GB_QUANTITY; index++)
  5602. {
  5603. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5604. {
  5605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5606. }
  5607. }
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_DO)
  5610. {
  5611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5614. {
  5615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5616. }
  5617. }
  5618. }
  5619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5625. } // END FOR DC CASE
  5626. }
  5627. // ================================= Current.Import L2 ===============================================
  5628. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5629. {
  5630. // AC 3 phse L2 current
  5631. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5632. {
  5633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5634. {
  5635. tempIndex = 2;
  5636. }
  5637. else
  5638. {
  5639. tempIndex = gun_index;
  5640. }
  5641. for (int index = 0; index < AC_QUANTITY; index++)
  5642. {
  5643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5644. {
  5645. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5646. }
  5647. }// End of for AC_QUANTITY
  5648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5649. }
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5655. }
  5656. // ================================= Current.Import L3 ===============================================
  5657. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5658. {
  5659. // AC 3 phse L3 current
  5660. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5661. {
  5662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5663. {
  5664. tempIndex = 2;
  5665. }
  5666. else
  5667. {
  5668. tempIndex = gun_index;
  5669. }
  5670. for (int index = 0; index < AC_QUANTITY; index++)
  5671. {
  5672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5673. {
  5674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5675. }
  5676. }// End of for AC_QUANTITY
  5677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5678. }
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5684. }
  5685. //============================ Voltage L2 ====================================
  5686. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5687. {
  5688. // AC 3 phse L2 voltage
  5689. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5690. {
  5691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5692. {
  5693. tempIndex = 2;
  5694. }
  5695. else
  5696. {
  5697. tempIndex = gun_index;
  5698. }
  5699. for (int index = 0; index < AC_QUANTITY; index++)
  5700. {
  5701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5702. {
  5703. 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
  5704. }
  5705. } // END OF FOR AC_QUANTITY
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5707. }
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5711. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5713. }
  5714. //============================ Voltage L3 ====================================
  5715. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5716. {
  5717. // AC 3 phse L3 voltage
  5718. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5719. {
  5720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5721. {
  5722. tempIndex = 2;
  5723. }
  5724. else
  5725. {
  5726. tempIndex = gun_index;
  5727. }
  5728. for (int index = 0; index < AC_QUANTITY; index++)
  5729. {
  5730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5731. {
  5732. 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
  5733. }
  5734. } // END OF FOR AC_QUANTITY
  5735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5736. }
  5737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5742. }
  5743. //====================== Start SoC ================================
  5744. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5745. {
  5746. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5747. 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))
  5748. {
  5749. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5758. {
  5759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5762. {
  5763. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5764. }
  5765. }
  5766. }
  5767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5768. {
  5769. for (int index = 0; index < CCS_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5774. }
  5775. }
  5776. }
  5777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5778. {
  5779. for (int index = 0; index < GB_QUANTITY; index++)
  5780. {
  5781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5782. {
  5783. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5784. }
  5785. }
  5786. }
  5787. else if(gunType[gun_index] == GUN_TYPE_DO)
  5788. {
  5789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5790. {
  5791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5792. {
  5793. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5794. }
  5795. }
  5796. }
  5797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5803. } // END FOR DC CASE
  5804. }
  5805. //================================================ Message create ====================================================
  5806. json_object *StopTransaction = json_object_new_object();
  5807. json_object *transactionDatas = json_object_new_array();
  5808. json_object *sampledValues = json_object_new_array();
  5809. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5810. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5811. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5812. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5813. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5814. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5815. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5816. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5817. {
  5818. json_object *transactionData = json_object_new_object();
  5819. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5820. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5821. {
  5822. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5823. {
  5824. json_object *sampledValue = json_object_new_object();
  5825. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5826. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5827. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5828. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5829. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5830. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5831. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5832. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5833. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5834. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5835. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5836. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5837. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5838. json_object_array_add(sampledValues, sampledValue);
  5839. }
  5840. }
  5841. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5842. json_object_array_add(transactionDatas, transactionData);
  5843. }
  5844. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5845. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5846. ,MESSAGE_TYPE_CALL
  5847. ,guid
  5848. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5849. json_object_put(StopTransaction);
  5850. #if 1 // for TempStopTransaction
  5851. //Delete TempStopTransaction
  5852. if((access(TempStopTransaction,F_OK))!=-1)
  5853. {
  5854. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5855. }
  5856. #endif
  5857. #if 1
  5858. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5859. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5860. {
  5861. result = PASS;
  5862. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5863. }
  5864. #endif
  5865. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5866. OCPP_insert_transaction_msg(NO, queuedata);
  5867. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5868. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5869. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5870. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5871. {
  5872. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5873. }
  5874. //for test
  5875. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5876. return result;
  5877. }
  5878. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5879. {
  5880. mtrace();
  5881. int result = FAIL;
  5882. char guid[37]={0};
  5883. char tempdata[65]={0};
  5884. int tempIndex = 0;
  5885. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5886. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5887. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5888. //set value
  5889. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5890. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5891. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5892. -1);
  5893. random_uuid(guid);
  5894. //UTC Date time
  5895. struct timeval tmnow;
  5896. struct tm *tm;
  5897. char buf[28];//, usec_buf[6];
  5898. gettimeofday(&tmnow, NULL);
  5899. time_t t;
  5900. t = time(NULL);
  5901. /*UTC time and date*/
  5902. tm = gmtime(&t);
  5903. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5904. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5905. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5906. //********************************(1)Current.Import L1************************************************/
  5907. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5908. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5909. (dataType == ReadingContext_Trigger))
  5910. {
  5911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5927. }
  5928. }
  5929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5934. {
  5935. tempIndex = ((gun_index==2) ? 1: 0);
  5936. }
  5937. else
  5938. {
  5939. tempIndex = gun_index;
  5940. }
  5941. for (int index = 0; index < CCS_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5944. {
  5945. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5946. }
  5947. }
  5948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5949. }
  5950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5951. {
  5952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5953. {
  5954. tempIndex = ((gun_index==2) ? 1: 0);
  5955. }
  5956. else
  5957. {
  5958. tempIndex = gun_index;
  5959. }
  5960. for (int index = 0; index < GB_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5965. }
  5966. }
  5967. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5968. }
  5969. else if(gunType[gun_index] == GUN_TYPE_DO)
  5970. {
  5971. tempIndex = gun_index;
  5972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5980. }
  5981. else
  5982. {
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. tempIndex = 2;
  5986. }
  5987. else
  5988. {
  5989. tempIndex = gun_index;
  5990. }
  5991. for (int index = 0; index < AC_QUANTITY; index++)
  5992. {
  5993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5994. {
  5995. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5996. }
  5997. }
  5998. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5999. }
  6000. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6003. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6004. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6005. }
  6006. //********************************(2)Energy.Active.Import.Register ************************************************/
  6007. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6008. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6009. (dataType == ReadingContext_Trigger))
  6010. {
  6011. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6012. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6013. {
  6014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6015. {
  6016. tempIndex = ((gun_index==2) ? 1: 0);
  6017. }
  6018. else
  6019. {
  6020. tempIndex = gun_index;
  6021. }
  6022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6027. }
  6028. }
  6029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6030. }
  6031. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6032. {
  6033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6034. {
  6035. tempIndex = ((gun_index==2) ? 1: 0);
  6036. }
  6037. else
  6038. {
  6039. tempIndex = gun_index;
  6040. }
  6041. for (int index = 0; index < CCS_QUANTITY; index++)
  6042. {
  6043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6044. {
  6045. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6046. }
  6047. }
  6048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6049. }
  6050. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6051. {
  6052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6053. {
  6054. tempIndex = ((gun_index==2) ? 1: 0);
  6055. }
  6056. else
  6057. {
  6058. tempIndex = gun_index;
  6059. }
  6060. for (int index = 0; index < GB_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6063. {
  6064. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6065. }
  6066. }
  6067. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6068. }
  6069. else if(gunType[gun_index] == GUN_TYPE_DO)
  6070. {
  6071. tempIndex = gun_index;
  6072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6077. }
  6078. }
  6079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6080. }
  6081. else
  6082. {
  6083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6084. {
  6085. tempIndex = 2;
  6086. }
  6087. else
  6088. {
  6089. tempIndex = gun_index;
  6090. }
  6091. for (int index = 0; index < AC_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6094. {
  6095. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6096. }
  6097. }
  6098. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6099. }
  6100. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6102. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6105. }
  6106. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6107. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6108. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6109. (dataType == ReadingContext_Trigger))
  6110. {
  6111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6113. {
  6114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6115. {
  6116. tempIndex = ((gun_index==2) ? 1: 0);
  6117. }
  6118. else
  6119. {
  6120. tempIndex = gun_index;
  6121. }
  6122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6123. {
  6124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6125. {
  6126. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6127. }
  6128. } // END OF FOR CHAdeMO_QUANTITY
  6129. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6132. {
  6133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6134. {
  6135. tempIndex = ((gun_index==2) ? 1: 0);
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. for (int index = 0; index < CCS_QUANTITY; index++)
  6142. {
  6143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6144. {
  6145. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6146. }
  6147. } // END OF CCS_QUANTITY
  6148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6149. }
  6150. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6151. {
  6152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6153. {
  6154. tempIndex = ((gun_index==2) ? 1: 0);
  6155. }
  6156. else
  6157. {
  6158. tempIndex = gun_index;
  6159. }
  6160. for (int index = 0; index < GB_QUANTITY; index++)
  6161. {
  6162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6163. {
  6164. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6165. }
  6166. } // END OF GB_QUANTITY
  6167. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6168. }
  6169. else if(gunType[gun_index] == GUN_TYPE_DO)
  6170. {
  6171. tempIndex = gun_index;
  6172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6175. {
  6176. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6177. }
  6178. }
  6179. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6180. }
  6181. else
  6182. {
  6183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6184. {
  6185. tempIndex = 2;
  6186. }
  6187. else
  6188. {
  6189. tempIndex = gun_index;
  6190. }
  6191. for (int index = 0; index < AC_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6194. {
  6195. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6196. }
  6197. }
  6198. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6199. }
  6200. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6201. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6202. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6203. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6204. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6205. }
  6206. //********************************(4)Power.Active.Import************************************************/
  6207. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6208. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6209. (dataType == ReadingContext_Trigger))
  6210. {
  6211. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6212. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6215. {
  6216. tempIndex = ((gun_index==2) ? 1: 0);
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6227. }
  6228. } // END OF FOR
  6229. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6232. {
  6233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6234. {
  6235. tempIndex = ((gun_index==2) ? 1: 0);
  6236. }
  6237. else
  6238. {
  6239. tempIndex = gun_index;
  6240. }
  6241. for (int index = 0; index < CCS_QUANTITY; index++)
  6242. {
  6243. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6244. {
  6245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6246. }
  6247. }
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6249. }
  6250. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6251. {
  6252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6253. {
  6254. tempIndex = ((gun_index==2) ? 1: 0);
  6255. }
  6256. else
  6257. {
  6258. tempIndex = gun_index;
  6259. }
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6263. {
  6264. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6265. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6266. }
  6267. }
  6268. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6269. }
  6270. else if(gunType[gun_index] == GUN_TYPE_DO)
  6271. {
  6272. tempIndex = gun_index;
  6273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6276. {
  6277. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6278. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6279. }
  6280. }
  6281. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6282. }
  6283. else
  6284. {
  6285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6286. {
  6287. tempIndex = 2;
  6288. }
  6289. else
  6290. {
  6291. tempIndex = gun_index;
  6292. }
  6293. for (int index = 0; index < AC_QUANTITY; index++)
  6294. {
  6295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6296. {
  6297. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6298. }
  6299. }
  6300. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6301. }
  6302. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6303. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6304. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6305. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6307. }
  6308. //***********************************************(5)VOLTAGE L1******************************************************/
  6309. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6310. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6311. (dataType == ReadingContext_Trigger))
  6312. {
  6313. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6315. {
  6316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6317. {
  6318. tempIndex = ((gun_index==2) ? 1: 0);
  6319. }
  6320. else
  6321. {
  6322. tempIndex = gun_index;
  6323. }
  6324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6325. {
  6326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6327. {
  6328. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6329. }
  6330. }
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6332. }
  6333. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6334. {
  6335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. for (int index = 0; index < CCS_QUANTITY; index++)
  6344. {
  6345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6346. {
  6347. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6348. }
  6349. }
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6351. }
  6352. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6355. {
  6356. tempIndex = ((gun_index==2) ? 1: 0);
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < GB_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6365. {
  6366. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6370. }
  6371. else if(gunType[gun_index] == GUN_TYPE_DO)
  6372. {
  6373. tempIndex = gun_index;
  6374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6375. {
  6376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6377. {
  6378. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6379. }
  6380. }
  6381. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6382. }
  6383. else
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6386. {
  6387. tempIndex = 2;
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. for (int index = 0; index < AC_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6398. }
  6399. }
  6400. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6401. }
  6402. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6403. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6404. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6407. }
  6408. //***********************************************(6)SOC******************************************************/
  6409. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6410. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6411. (dataType == ReadingContext_Trigger))
  6412. {
  6413. 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))
  6414. {
  6415. //idx_sample=5;
  6416. //sampledValue = NULL;
  6417. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6418. {
  6419. tempIndex = ((gun_index==2) ? 1: 0);
  6420. }
  6421. else
  6422. {
  6423. tempIndex = gun_index;
  6424. }
  6425. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6426. {
  6427. //tempIndex = ((gun_index==2) ? 1: 0);
  6428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6429. {
  6430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6431. {
  6432. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6433. }
  6434. }
  6435. }
  6436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6437. {
  6438. //tempIndex = ((gun_index==2) ? 1: 0);
  6439. for (int index = 0; index < CCS_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6444. }
  6445. }
  6446. }
  6447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6448. {
  6449. //tempIndex = ((gun_index==2) ? 1: 0);
  6450. for (int index = 0; index < GB_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6453. {
  6454. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6455. }
  6456. }
  6457. }
  6458. else if(gunType[gun_index] == GUN_TYPE_DO)
  6459. {
  6460. //tempIndex = ((gun_index==2) ? 1: 0);
  6461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6462. {
  6463. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6464. {
  6465. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6466. }
  6467. }
  6468. }
  6469. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6470. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6471. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6473. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6475. }
  6476. }
  6477. //********************************(7)Current.Import L2************************************************/
  6478. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6479. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6480. (dataType == ReadingContext_Trigger))
  6481. {
  6482. // Only for AC 3 phase
  6483. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6484. {
  6485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6486. {
  6487. tempIndex = 2;
  6488. }
  6489. else
  6490. {
  6491. tempIndex = gun_index;
  6492. }
  6493. for (int index = 0; index < AC_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6498. }
  6499. }
  6500. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6501. }
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6503. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6507. }
  6508. //********************************(8)Current.Import L3************************************************/
  6509. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6510. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6511. (dataType == ReadingContext_Trigger))
  6512. {
  6513. // Only for AC 3 phase
  6514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6515. {
  6516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6517. {
  6518. tempIndex = 2;
  6519. }
  6520. else
  6521. {
  6522. tempIndex = gun_index;
  6523. }
  6524. for (int index = 0; index < AC_QUANTITY; index++)
  6525. {
  6526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6527. {
  6528. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6529. }
  6530. }
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6532. }
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6538. }
  6539. //***********************************************(9)VOLTAGE L2******************************************************/
  6540. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6541. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6542. (dataType == ReadingContext_Trigger))
  6543. {
  6544. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6547. {
  6548. tempIndex = 2;
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < AC_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6559. }
  6560. }
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6562. }
  6563. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6564. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6565. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6567. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6568. }
  6569. //***********************************************(10)VOLTAGE L3******************************************************/
  6570. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6571. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6572. (dataType == ReadingContext_Trigger))
  6573. {
  6574. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6575. {
  6576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6577. {
  6578. tempIndex = 2;
  6579. }
  6580. else
  6581. {
  6582. tempIndex = gun_index;
  6583. }
  6584. for (int index = 0; index < AC_QUANTITY; index++)
  6585. {
  6586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6587. {
  6588. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6589. }
  6590. }
  6591. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6592. }
  6593. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6596. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6598. }
  6599. //***********************************************(11)Current.Offered******************************************************/
  6600. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6601. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6602. (dataType == ReadingContext_Trigger))
  6603. {
  6604. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6605. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6606. {
  6607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6608. {
  6609. tempIndex = ((gun_index==2) ? 1: 0);
  6610. }
  6611. else
  6612. {
  6613. tempIndex = gun_index;
  6614. }
  6615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6616. {
  6617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6618. {
  6619. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6620. }
  6621. } // END OF FOR CHAdeMO_QUANTITY
  6622. }
  6623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6624. {
  6625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6626. {
  6627. tempIndex = ((gun_index==2) ? 1: 0);
  6628. }
  6629. else
  6630. {
  6631. tempIndex = gun_index;
  6632. }
  6633. for (int index = 0; index < CCS_QUANTITY; index++)
  6634. {
  6635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6636. {
  6637. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6638. }
  6639. } // END OF CCS_QUANTITY
  6640. }
  6641. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6642. {
  6643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6644. {
  6645. tempIndex = ((gun_index==2) ? 1: 0);
  6646. }
  6647. else
  6648. {
  6649. tempIndex = gun_index;
  6650. }
  6651. for (int index = 0; index < GB_QUANTITY; index++)
  6652. {
  6653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6654. {
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6656. }
  6657. } // END OF GB_QUANTITY
  6658. }
  6659. else if(gunType[gun_index] == GUN_TYPE_DO)
  6660. {
  6661. tempIndex = gun_index;
  6662. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6663. {
  6664. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6665. {
  6666. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6667. }
  6668. }
  6669. }
  6670. else
  6671. {
  6672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6673. {
  6674. tempIndex = 2;
  6675. }
  6676. else
  6677. {
  6678. tempIndex = gun_index;
  6679. }
  6680. for (int index = 0; index < AC_QUANTITY; index++)
  6681. {
  6682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6683. {
  6684. uint16_t currentOffer;
  6685. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6686. {
  6687. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6688. }
  6689. else
  6690. {
  6691. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6692. }
  6693. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6694. }
  6695. }
  6696. }
  6697. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6702. }
  6703. //***********************************************(12)Power.Offered******************************************************/
  6704. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6705. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6706. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6707. {
  6708. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6710. {
  6711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6712. {
  6713. tempIndex = ((gun_index==2) ? 1: 0);
  6714. }
  6715. else
  6716. {
  6717. tempIndex = gun_index;
  6718. }
  6719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6720. {
  6721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6722. {
  6723. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6724. }
  6725. } // END OF FOR CHAdeMO_QUANTITY
  6726. }
  6727. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6730. {
  6731. tempIndex = ((gun_index==2) ? 1: 0);
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < CCS_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6742. }
  6743. } // END OF CCS_QUANTITY
  6744. }
  6745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6746. {
  6747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6748. {
  6749. tempIndex = ((gun_index==2) ? 1: 0);
  6750. }
  6751. else
  6752. {
  6753. tempIndex = gun_index;
  6754. }
  6755. for (int index = 0; index < GB_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6758. {
  6759. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6760. }
  6761. } // END OF GB_QUANTITY
  6762. }
  6763. else if(gunType[gun_index] == GUN_TYPE_DO)
  6764. {
  6765. tempIndex = gun_index;
  6766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6769. {
  6770. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6771. }
  6772. }
  6773. }
  6774. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6775. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6776. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6778. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6779. }
  6780. // Message create ====================================================================================================
  6781. if(TRUE)
  6782. {
  6783. json_object *MeterValueReq = json_object_new_object();
  6784. json_object *MeterValues = json_object_new_array();
  6785. json_object *sampledValues = json_object_new_array();
  6786. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6787. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6788. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6789. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6790. {
  6791. json_object *MeterValue = json_object_new_object();
  6792. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6793. {
  6794. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6795. {
  6796. json_object *sampledValue = json_object_new_object();
  6797. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6798. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6799. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6800. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6801. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6802. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6803. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6804. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6805. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6806. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6807. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6808. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6809. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6810. json_object_array_add(sampledValues, sampledValue);
  6811. }
  6812. }
  6813. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6814. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6815. json_object_array_add(MeterValues, MeterValue);
  6816. }
  6817. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6818. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6819. ,gun_index + 1
  6820. ,MESSAGE_TYPE_CALL
  6821. ,guid
  6822. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6823. json_object_put(MeterValueReq);
  6824. }
  6825. // Put request guid to hash map
  6826. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6827. 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*/)
  6828. {
  6829. result = PASS;
  6830. //DEBUG_INFO("MeterValues mapitem pass\n");
  6831. }
  6832. if((dataType != ReadingContext_Trigger) &&
  6833. (dataType != ReadingContext_Sample_Clock) &&
  6834. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6835. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6836. else
  6837. {
  6838. if(FirstHeartBeat)
  6839. LWS_Send(queuedata +2);
  6840. }
  6841. return result;
  6842. }
  6843. int sendLogStatusNotificationRequest(char *status)
  6844. {
  6845. mtrace();
  6846. int result = PASS;
  6847. char message[4096]={0};
  6848. char guid[37]={0};
  6849. char tempdata[128]={0};
  6850. json_object *LogStatusNotification = json_object_new_object();
  6851. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6852. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6853. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6854. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6855. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6856. random_uuid(guid);
  6857. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6858. json_object_put(LogStatusNotification);
  6859. LWS_Send(message);
  6860. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6861. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6862. {
  6863. result = PASS;
  6864. }
  6865. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6866. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6867. return result;
  6868. }
  6869. int sendSecurityEventNotificationRequest()
  6870. {
  6871. mtrace();
  6872. int result = PASS;
  6873. char message[4096]={0};
  6874. char guid[37]={0};
  6875. char tempdata[128]={0};
  6876. json_object *SecurityEventNotification = json_object_new_object();
  6877. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6878. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6879. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6880. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6881. random_uuid(guid);
  6882. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6883. json_object_put(SecurityEventNotification);
  6884. LWS_Send(message);
  6885. sprintf(tempdata, "SecurityEventNotification,0");
  6886. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6887. {
  6888. result = PASS;
  6889. }
  6890. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6891. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6892. return result;
  6893. }
  6894. int sendSignCertificateRequest()
  6895. {
  6896. mtrace();
  6897. int result = PASS;
  6898. char message[4096]={0};
  6899. char guid[37]={0};
  6900. char tempdata[128]={0};
  6901. json_object *SignCertificate = json_object_new_object();
  6902. DEBUG_INFO("sendSignCertificateRequest...\n");
  6903. // Read csr file content
  6904. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6905. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6906. char *line = NULL;
  6907. size_t len = 0;
  6908. while(getline(&line, &len, fp) != -1)
  6909. {
  6910. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6911. {
  6912. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6913. }
  6914. }
  6915. fclose(fp);
  6916. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6917. random_uuid(guid);
  6918. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6919. json_object_put(SignCertificate);
  6920. LWS_Send(message);
  6921. sprintf(tempdata, "SignCertificate,0");
  6922. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6923. {
  6924. result = PASS;
  6925. }
  6926. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6927. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6928. return result;
  6929. }
  6930. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6931. {
  6932. mtrace();
  6933. int result = PASS;
  6934. char message[110]={0};
  6935. char guid[37]={0};
  6936. char tempdata[65]={0};
  6937. json_object *FirmwareStatusNotification = json_object_new_object();
  6938. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6939. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6940. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6941. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6942. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6943. random_uuid(guid);
  6944. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6945. json_object_put(FirmwareStatusNotification);
  6946. LWS_Send(message);
  6947. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6948. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6949. {
  6950. result = PASS;
  6951. }
  6952. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6953. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6954. return result;
  6955. }
  6956. //==========================================
  6957. // send confirm routine
  6958. //==========================================
  6959. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6960. {
  6961. mtrace();
  6962. int result = FAIL;
  6963. char message[100]={0};
  6964. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6965. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6966. LWS_Send(message);
  6967. result = TRUE;
  6968. return result;
  6969. }
  6970. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6971. {
  6972. mtrace();
  6973. int result = FAIL;
  6974. char message[100]={0};
  6975. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6977. LWS_Send(message);
  6978. result = TRUE;
  6979. return result;
  6980. }
  6981. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6982. {
  6983. mtrace();
  6984. int result = FAIL;
  6985. char message[100]={0};
  6986. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6988. LWS_Send(message);
  6989. result = TRUE;
  6990. return result;
  6991. }
  6992. int sendClearCacheConfirmation(char *uuid,char *payload)
  6993. {
  6994. mtrace();
  6995. int result = FAIL;
  6996. char message[500]={0};
  6997. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6998. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6999. LWS_Send(message);
  7000. return result;
  7001. }
  7002. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7003. {
  7004. mtrace();
  7005. int result = FAIL;
  7006. char message[500]={0};
  7007. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7008. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7009. LWS_Send(message);
  7010. return result;
  7011. }
  7012. int sendDataTransferConfirmation(char *uuid,char *payload)
  7013. {
  7014. mtrace();
  7015. char statusStr[20]={0};
  7016. char dataStr[10]={0};
  7017. char sstr[20]={0};
  7018. int c = 0;
  7019. char *loc;
  7020. int result = FAIL;
  7021. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7022. /**********************status**************************/
  7023. loc = strstr(payload, "status");
  7024. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7025. c = 0;
  7026. while (loc[3+strlen("status")+c] != '\"')
  7027. {
  7028. sstr[c] = loc[3+strlen("status")+c];
  7029. c++;
  7030. }
  7031. sstr[c] = '\0';
  7032. strcpy(statusStr, sstr);
  7033. /**********************data**************************/
  7034. loc = strstr(payload, "data");
  7035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7036. c = 0;
  7037. while (loc[3+strlen("data")+c] != '\"')
  7038. {
  7039. sstr[c] = loc[3+strlen("data")+c];
  7040. c++;
  7041. }
  7042. sstr[c] = '\0';
  7043. strcpy(dataStr, sstr);
  7044. return result;
  7045. }
  7046. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7047. {
  7048. mtrace();
  7049. int result = FAIL;
  7050. char message[1000]={0};
  7051. int CompositeScheduleIndex = 0;
  7052. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7053. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7054. if(nPeriod == 0)
  7055. {
  7056. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7057. {
  7058. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7059. ,MESSAGE_TYPE_CALLRESULT
  7060. ,uuid
  7061. ,payload
  7062. ,connectorIdInt);
  7063. }
  7064. else
  7065. {
  7066. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7067. ,MESSAGE_TYPE_CALLRESULT
  7068. ,uuid
  7069. ,payload
  7070. ,connectorIdInt
  7071. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7072. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7073. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7074. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7075. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7076. }
  7077. }
  7078. else
  7079. {
  7080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7081. ,MESSAGE_TYPE_CALLRESULT
  7082. ,uuid
  7083. ,payload
  7084. ,connectorIdInt
  7085. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7086. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7087. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7088. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7089. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7090. {
  7091. if (idx_sample == 0)
  7092. {
  7093. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7094. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7095. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7096. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7097. }
  7098. else
  7099. {
  7100. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7101. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7102. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7103. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7104. }
  7105. }
  7106. sprintf(message + strlen(message), "]}}]");
  7107. }
  7108. LWS_Send(message);
  7109. result = TRUE;
  7110. return result;
  7111. }
  7112. int sendGetConfigurationConfirmation(char *uuid)
  7113. {
  7114. mtrace();
  7115. int result = FAIL;
  7116. int MaxKeySupported = 0;
  7117. int sentConfigurationNumber= 0;
  7118. int sentunConfigurationNumber= 0;
  7119. char message[1024*10]={0};
  7120. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7121. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7122. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7123. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7124. ,MESSAGE_TYPE_CALLRESULT
  7125. ,uuid );
  7126. //configuration key
  7127. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7128. {
  7129. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7130. {
  7131. if (sentConfigurationNumber == 0)
  7132. {
  7133. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7134. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7135. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7136. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7137. }
  7138. else
  7139. {
  7140. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7141. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7142. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7143. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7144. }
  7145. sentConfigurationNumber = sentConfigurationNumber + 1;
  7146. }
  7147. }
  7148. sprintf(message + strlen(message), "]");
  7149. if(UnknownKeynum != 0)
  7150. {
  7151. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7152. //unkown key
  7153. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7154. {
  7155. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7156. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7157. if(sentunConfigurationNumber == 0)
  7158. {
  7159. sprintf(message + strlen(message), "\"%s\""
  7160. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7161. }
  7162. else
  7163. {
  7164. sprintf(message + strlen(message), ",\"%s\""
  7165. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7166. }
  7167. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7168. }
  7169. sprintf(message + strlen(message), "]");
  7170. }
  7171. sprintf(message + strlen(message), "}]");
  7172. LWS_Send(message);
  7173. return result;
  7174. }
  7175. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7176. {
  7177. mtrace();
  7178. int result = FAIL;
  7179. char message[400]={0};
  7180. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7181. if(strcmp(payload,"")==0)
  7182. {
  7183. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7184. }
  7185. else
  7186. {
  7187. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7188. }
  7189. LWS_Send(message);
  7190. result = TRUE;
  7191. return result;
  7192. }
  7193. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7194. {
  7195. mtrace();
  7196. int result = FAIL;
  7197. char message[80]={0};
  7198. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7199. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7200. LWS_Send(message);
  7201. result = TRUE;
  7202. return result;
  7203. }
  7204. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7205. {
  7206. mtrace();
  7207. int result = FAIL;
  7208. char message[80]={0};
  7209. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7210. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7211. LWS_Send(message);
  7212. result = TRUE;
  7213. return result;
  7214. }
  7215. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7216. {
  7217. mtrace();
  7218. int result = FAIL;
  7219. char message[80]={0};
  7220. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7221. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7222. LWS_Send(message);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7227. {
  7228. mtrace();
  7229. int result = FAIL;
  7230. char message[80]={0};
  7231. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7232. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7234. LWS_Send(message);
  7235. result = TRUE;
  7236. return result;
  7237. }
  7238. int sendResetConfirmation(char *uuid,char *payload)
  7239. {
  7240. mtrace();
  7241. int result = FAIL;
  7242. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7243. char message[80]={0};
  7244. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7245. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7246. LWS_Send(message);
  7247. result = TRUE;
  7248. return result;
  7249. }
  7250. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7251. {
  7252. mtrace();
  7253. int result = FAIL;
  7254. char message[500]={0};
  7255. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7256. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7257. LWS_Send(message);
  7258. result = TRUE;
  7259. return result;
  7260. }
  7261. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7262. {
  7263. mtrace();
  7264. int result = FAIL;
  7265. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7266. char message[80]={0};
  7267. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7268. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7269. LWS_Send(message);
  7270. result = TRUE;
  7271. return result;
  7272. }
  7273. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7274. {
  7275. mtrace();
  7276. int result = FAIL;
  7277. char message[80]={0};
  7278. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7279. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7280. LWS_Send(message);
  7281. result = TRUE;
  7282. return result;
  7283. }
  7284. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7285. {
  7286. mtrace();
  7287. int result = FAIL;
  7288. char message[80]={0};
  7289. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7290. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7292. LWS_Send(message);
  7293. result = TRUE;
  7294. return result;
  7295. }
  7296. int sendUpdateFirmwareConfirmation(char *uuid)
  7297. {
  7298. mtrace();
  7299. int result = FAIL;
  7300. char message[60]={0};
  7301. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7302. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7303. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7304. LWS_Send(message);
  7305. result = TRUE;
  7306. return result;
  7307. }
  7308. int sendCertificateSignedConfirmation(char *uuid)
  7309. {
  7310. mtrace();
  7311. int result = PASS;
  7312. char message[4096]={0};
  7313. json_object *CertificateSigned = json_object_new_object();
  7314. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7315. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7316. sprintf(message,"[%d,\"%s\",%s]"
  7317. ,MESSAGE_TYPE_CALLRESULT
  7318. ,uuid
  7319. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7320. json_object_put(CertificateSigned);
  7321. LWS_Send(message);
  7322. return result;
  7323. }
  7324. int sendDeleteCertificateConfirmation(char *uuid)
  7325. {
  7326. mtrace();
  7327. int result = PASS;
  7328. char message[4096]={0};
  7329. json_object *DeleteCertificate = json_object_new_object();
  7330. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7331. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7332. sprintf(message,"[%d,\"%s\",%s]"
  7333. ,MESSAGE_TYPE_CALLRESULT
  7334. ,uuid
  7335. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7336. json_object_put(DeleteCertificate);
  7337. LWS_Send(message);
  7338. return result;
  7339. }
  7340. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7341. {
  7342. mtrace();
  7343. int result = PASS;
  7344. char message[4096]={0};
  7345. json_object *ExtendedTriggerMessage = json_object_new_object();
  7346. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7347. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7348. sprintf(message,"[%d,\"%s\",%s]"
  7349. ,MESSAGE_TYPE_CALLRESULT
  7350. ,uuid
  7351. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7352. json_object_put(ExtendedTriggerMessage);
  7353. LWS_Send(message);
  7354. return result;
  7355. }
  7356. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7357. {
  7358. mtrace();
  7359. int result = PASS;
  7360. char message[4096]={0};
  7361. json_object *GetInstalledCertificateIds = json_object_new_object();
  7362. json_object *certificateHashDataDatas = json_object_new_array();
  7363. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7364. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7365. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7366. {
  7367. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7368. {
  7369. json_object *certificateHashData = json_object_new_object();
  7370. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7371. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7372. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7373. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7374. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7375. }
  7376. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7377. }
  7378. else
  7379. {
  7380. json_object_put(certificateHashDataDatas);
  7381. }
  7382. sprintf(message,"[%d,\"%s\",%s]"
  7383. ,MESSAGE_TYPE_CALLRESULT
  7384. ,uuid
  7385. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7386. json_object_put(GetInstalledCertificateIds);
  7387. LWS_Send(message);
  7388. return result;
  7389. }
  7390. int sendGetLogConfirmation(char *uuid)
  7391. {
  7392. mtrace();
  7393. int result = PASS;
  7394. char message[4096]={0};
  7395. json_object *GetLog = json_object_new_object();
  7396. DEBUG_INFO("sendGetLogConfirmation...\n");
  7397. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7398. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7399. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7400. sprintf(message,"[%d,\"%s\",%s]"
  7401. ,MESSAGE_TYPE_CALLRESULT
  7402. ,uuid
  7403. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7404. json_object_put(GetLog);
  7405. LWS_Send(message);
  7406. return result;
  7407. }
  7408. int sendInstallCertificateConfirmation(char *uuid)
  7409. {
  7410. mtrace();
  7411. int result = PASS;
  7412. char message[4096]={0};
  7413. json_object *InstallCertificate = json_object_new_object();
  7414. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7415. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7416. sprintf(message,"[%d,\"%s\",%s]"
  7417. ,MESSAGE_TYPE_CALLRESULT
  7418. ,uuid
  7419. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7420. json_object_put(InstallCertificate);
  7421. LWS_Send(message);
  7422. return result;
  7423. }
  7424. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7425. {
  7426. mtrace();
  7427. int result = PASS;
  7428. char message[4096]={0};
  7429. json_object *SignedUpdateFirmware = json_object_new_object();
  7430. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7431. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7432. sprintf(message,"[%d,\"%s\",%s]"
  7433. ,MESSAGE_TYPE_CALLRESULT
  7434. ,uuid
  7435. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7436. json_object_put(SignedUpdateFirmware);
  7437. LWS_Send(message);
  7438. return result;
  7439. }
  7440. int sendUnknownConfirmation(char *uuid)
  7441. {
  7442. mtrace();
  7443. int result = PASS;
  7444. char message[256]={0};
  7445. DEBUG_INFO("sendUnknownConfirmation...\n");
  7446. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7447. LWS_Send(message);
  7448. return result;
  7449. }
  7450. //==========================================
  7451. // Handle server request routine Start
  7452. //==========================================
  7453. int handleCancelReservationRequest(char *uuid, char *payload)
  7454. {
  7455. mtrace();
  7456. int result = FAIL;
  7457. int gunNO = 0;
  7458. int reservationIdInt = -1;
  7459. char comfirmstr[20];
  7460. DEBUG_INFO("handleCancelReservationRequest...\n");
  7461. json_object *CancelReservation;
  7462. CancelReservation = json_tokener_parse(payload);
  7463. if(!is_error(CancelReservation))
  7464. {
  7465. // Required data
  7466. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7467. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7468. }
  7469. json_object_put(CancelReservation);
  7470. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7471. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7472. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7473. if(reservationIdInt != -1)
  7474. {
  7475. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7476. //check Transaction active
  7477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7481. {
  7482. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7483. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7484. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7485. {
  7486. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7487. }
  7488. else
  7489. {
  7490. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7491. }
  7492. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7493. goto end;
  7494. }
  7495. }
  7496. for (int index = 0; index < CCS_QUANTITY; index++)
  7497. {
  7498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7499. {
  7500. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7501. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7502. if(gunType[2] == GUN_TYPE_CCS)
  7503. {
  7504. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7505. }
  7506. else
  7507. {
  7508. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7509. }
  7510. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7511. goto end;
  7512. }
  7513. }
  7514. for (int index = 0; index < GB_QUANTITY; index++)
  7515. {
  7516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7517. {
  7518. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7519. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7520. if(gunType[2] == GUN_TYPE_GBT)
  7521. {
  7522. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7523. }
  7524. else
  7525. {
  7526. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7527. }
  7528. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7529. goto end;
  7530. }
  7531. }
  7532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7533. {
  7534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7535. {
  7536. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7537. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7538. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7539. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7540. goto end;
  7541. }
  7542. }
  7543. for (int index = 0; index < AC_QUANTITY; index++)
  7544. {
  7545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7546. {
  7547. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7548. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7550. {
  7551. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7552. }
  7553. else
  7554. {
  7555. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7556. }
  7557. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7558. goto end;
  7559. }
  7560. }
  7561. }
  7562. //The reservationId does NOT match the reservationId
  7563. sendCancelReservationConfirmation(uuid, comfirmstr);
  7564. end:
  7565. // Fill in ocpp packet uuid
  7566. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7567. return result;
  7568. }
  7569. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7570. {
  7571. mtrace();
  7572. int result = FAIL;
  7573. int gunIndex = -1;
  7574. char typeStr[16]={0};
  7575. char comfirmstr[20];
  7576. int specificId = FALSE;
  7577. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7578. json_object *ChangeAvailability;
  7579. ChangeAvailability = json_tokener_parse(payload);
  7580. if(!is_error(ChangeAvailability))
  7581. {
  7582. // Required data
  7583. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7584. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7585. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7586. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7587. }
  7588. json_object_put(ChangeAvailability);
  7589. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7590. {
  7591. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7592. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7593. }
  7594. else if(gunIndex == 0)
  7595. {
  7596. for(int i=0; i < gunTotalNumber; i++)
  7597. {
  7598. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7599. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7600. }
  7601. }
  7602. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7604. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7605. {
  7606. specificId = TRUE;
  7607. }
  7608. if(specificId == FALSE)
  7609. goto end;
  7610. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7611. {
  7612. //----------------------gunIndex is 0 ------------------------------------------------//
  7613. if(gunIndex == 0)
  7614. {
  7615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7616. {
  7617. for(int i=0; i < gunTotalNumber; i++)
  7618. {
  7619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7620. {
  7621. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7622. {
  7623. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7624. {
  7625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7626. goto end;
  7627. }
  7628. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7632. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7633. {
  7634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7635. goto end;
  7636. }
  7637. }
  7638. }//END FOR CHAdeMO_QUANTITY
  7639. for (int index = 0; index < CCS_QUANTITY; index++)
  7640. {
  7641. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7642. {
  7643. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7644. {
  7645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7646. goto end;
  7647. }
  7648. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7655. goto end;
  7656. }
  7657. }
  7658. }//END FOR CCS_QUANTITY
  7659. for (int index = 0; index < GB_QUANTITY; index++)
  7660. {
  7661. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7662. {
  7663. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7664. {
  7665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7666. goto end;
  7667. }
  7668. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7669. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7673. {
  7674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7675. goto end;
  7676. }
  7677. }
  7678. }// END FOR GB_QUANTITY
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7682. {
  7683. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7684. {
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7686. goto end;
  7687. }
  7688. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7689. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7692. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7693. {
  7694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7695. goto end;
  7696. }
  7697. }
  7698. }// END FOR GENERAL_GUN_QUANTITY
  7699. for (int index = 0; index < AC_QUANTITY; index++)
  7700. {
  7701. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7704. {
  7705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7706. goto end;
  7707. }
  7708. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7709. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7712. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7713. {
  7714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7715. goto end;
  7716. }
  7717. }
  7718. }//END FOR AC_QUANTITY
  7719. }// END FOR gunTotalNumber
  7720. }
  7721. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7722. {
  7723. for(int i=0; i < gunTotalNumber; i++)
  7724. {
  7725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7726. {
  7727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7728. goto end;
  7729. }
  7730. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7732. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7733. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7734. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7735. {
  7736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7737. goto end;
  7738. }
  7739. }
  7740. }
  7741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7742. goto end;
  7743. }
  7744. //----------------------gunIndex is not 0 ------------------------------------------------//
  7745. //check Transaction active
  7746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7747. {
  7748. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7749. {
  7750. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7751. {
  7752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7753. goto end;
  7754. }
  7755. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7756. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7758. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7759. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7760. {
  7761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7762. goto end;
  7763. }
  7764. else
  7765. {
  7766. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7768. goto end;
  7769. }
  7770. }
  7771. }//END FOR CHAdeMO_QUANTITY
  7772. for (int index = 0; index < CCS_QUANTITY; index++)
  7773. {
  7774. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7775. {
  7776. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7777. {
  7778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7779. goto end;
  7780. }
  7781. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7782. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7783. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7785. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7786. {
  7787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7788. goto end;
  7789. }
  7790. else
  7791. {
  7792. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7794. goto end;
  7795. }
  7796. }
  7797. }//END FOR CCS_QUANTITY
  7798. for (int index = 0; index < GB_QUANTITY; index++)
  7799. {
  7800. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7801. {
  7802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7803. {
  7804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7805. goto end;
  7806. }
  7807. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7808. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7809. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7810. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7811. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7812. {
  7813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7814. goto end;
  7815. }
  7816. else
  7817. {
  7818. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7820. goto end;
  7821. }
  7822. }
  7823. }// END FOR GB_QUANTITY
  7824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7825. {
  7826. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7827. {
  7828. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7829. {
  7830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7831. goto end;
  7832. }
  7833. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7837. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7838. {
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7840. goto end;
  7841. }
  7842. else
  7843. {
  7844. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7846. goto end;
  7847. }
  7848. }
  7849. }// END FOR GENERAL_GUN_QUANTITY
  7850. for (int index = 0; index < AC_QUANTITY; index++)
  7851. {
  7852. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7853. {
  7854. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7855. {
  7856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7857. goto end;
  7858. }
  7859. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7860. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7863. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7864. {
  7865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7866. goto end;
  7867. }
  7868. else
  7869. {
  7870. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7872. goto end;
  7873. }
  7874. }
  7875. }//END FOR AC_QUANTITY
  7876. }//END FOR AvailabilityTypeStr[Inoperative]
  7877. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7878. {
  7879. //----------------------gunIndex is 0 ------------------------------------------------//
  7880. if(gunIndex == 0)
  7881. {
  7882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7883. {
  7884. for(int i=0; i < gunTotalNumber; i++)
  7885. {
  7886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7887. {
  7888. 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
  7889. {
  7890. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7891. goto end;
  7892. }
  7893. }//END FOR CHAdeMO_QUANTITY
  7894. for (int index = 0; index < CCS_QUANTITY; index++)
  7895. {
  7896. 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
  7897. {
  7898. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7899. goto end;
  7900. }
  7901. }//END FOR CCS_QUANTITY
  7902. for (int index = 0; index < GB_QUANTITY; index++)
  7903. {
  7904. 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
  7905. {
  7906. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7907. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7908. goto end;
  7909. }
  7910. }// END FOR GB_QUANTITY
  7911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7912. {
  7913. 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
  7914. {
  7915. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7917. goto end;
  7918. }
  7919. }// END FOR GENERAL_GUN_QUANTITY
  7920. for (int index = 0; index < AC_QUANTITY; index++)
  7921. {
  7922. 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
  7923. {
  7924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7925. goto end;
  7926. }
  7927. }//END FOR CHAdeMO_QUANTITY
  7928. }// END FOR gunTotalNumber
  7929. }
  7930. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7931. {
  7932. for(int i=0; i < gunTotalNumber; i++)
  7933. {
  7934. for (int index = 0; index < AC_QUANTITY; index++)
  7935. {
  7936. 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
  7937. {
  7938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7939. goto end;
  7940. }
  7941. }//END FOR CHAdeMO_QUANTITY
  7942. } // END FOR gunTotalNumber
  7943. }
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7945. goto end;
  7946. }
  7947. //----------------------gunIndex is not 0 ------------------------------------------------//
  7948. //check Transaction active
  7949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7950. {
  7951. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7952. {
  7953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7954. goto end;
  7955. }
  7956. }//END FOR CHAdeMO_QUANTITY
  7957. for (int index = 0; index < CCS_QUANTITY; index++)
  7958. {
  7959. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7960. {
  7961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7962. goto end;
  7963. }
  7964. }//END FOR CCS_QUANTITY
  7965. for (int index = 0; index < GB_QUANTITY; index++)
  7966. {
  7967. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7968. {
  7969. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7970. goto end;
  7971. }
  7972. }// END FOR GB_QUANTITY
  7973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7974. {
  7975. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7978. goto end;
  7979. }
  7980. }// END FOR GENERAL_GUN_QUANTITY
  7981. for (int index = 0; index < AC_QUANTITY; index++)
  7982. {
  7983. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7984. {
  7985. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7986. goto end;
  7987. }
  7988. }//END FOR AC_QUANTITY
  7989. }//END FOR AvailabilityTypeStr[Operative]
  7990. end:
  7991. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7992. {
  7993. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7994. }
  7995. else
  7996. {
  7997. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7998. }
  7999. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8000. {
  8001. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8002. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8003. }
  8004. else if(gunIndex == 0)
  8005. {
  8006. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8007. {
  8008. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8009. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8010. }
  8011. }
  8012. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8013. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8014. return result;
  8015. }
  8016. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8017. {
  8018. mtrace();
  8019. int valueInvalid = NO;
  8020. int result = FAIL;
  8021. char keystr[40]={0};
  8022. char valuestr[501]={0}; //value should be limited in 500 bytes
  8023. char comfirmstr[20]={0};
  8024. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8025. json_object *ChangeConfiguration;
  8026. ChangeConfiguration = json_tokener_parse(payload);
  8027. if(!is_error(ChangeConfiguration))
  8028. {
  8029. // Required data
  8030. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8031. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8032. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8033. {
  8034. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8035. }
  8036. else
  8037. {
  8038. valueInvalid = YES;
  8039. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8040. }
  8041. }
  8042. json_object_put(ChangeConfiguration);
  8043. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8044. {
  8045. DEBUG_ERROR("Payload is null or not accepted.\n");
  8046. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8047. }
  8048. else
  8049. {
  8050. int status = setKeyValue(keystr, valuestr);
  8051. switch(status)
  8052. {
  8053. case ConfigurationStatus_Accepted:
  8054. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8055. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8056. StoreConfigurationTable();
  8057. break;
  8058. case RebootRequired:
  8059. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8060. StoreConfigurationTable();
  8061. break;
  8062. case NotSupported:
  8063. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8064. break;
  8065. case ConfigurationStatus_Rejected:
  8066. default:
  8067. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8068. break;
  8069. }
  8070. }
  8071. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8072. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8073. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8074. {
  8075. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8076. SetOcppConnStatus(FALSE);
  8077. }
  8078. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8079. {
  8080. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8081. }
  8082. return result;
  8083. }
  8084. int handleClearCacheRequest(char *uuid, char *payload)
  8085. {
  8086. mtrace();
  8087. int result = FAIL;
  8088. char comfirmstr[20];
  8089. char rmFileCmd[100]={0};
  8090. struct stat stats;
  8091. DEBUG_INFO("handleClearCacheRequest...\n");
  8092. stat("/Storage/OCPP_PH", &stats);
  8093. // Check for directory existence
  8094. if (S_ISDIR(stats.st_mode) == 1)
  8095. {}
  8096. else
  8097. {
  8098. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8099. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8100. system(rmFileCmd);
  8101. }
  8102. if(OCPP_cleanLocalCache())
  8103. {
  8104. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8105. }
  8106. else
  8107. {
  8108. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8109. }
  8110. sendClearCacheConfirmation(uuid, comfirmstr);
  8111. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8112. return result;
  8113. }
  8114. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8115. {
  8116. mtrace();
  8117. int result = FAIL;
  8118. int resultRename;
  8119. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8120. char chargingProfilePurposeStr[26]={0};
  8121. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8122. char tempchargingProfilePurposeStr[26]={0};
  8123. char str[100]={0};
  8124. char fname[200]={0};
  8125. char comfirmstr[20]={0};
  8126. char word[1600]={0};
  8127. int clearflag = FALSE;
  8128. int chargingProfileIdIsNULL = FALSE;
  8129. int connectorIsNULL = FALSE;
  8130. int chargingProfilePurposeIsNULL = FALSE;
  8131. int stackLevelIsNULL = FALSE;
  8132. //int GotoEnd = FALSE;
  8133. FILE *fptr1, *fptr2;
  8134. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8135. int n_chargingProfile=0;
  8136. int isEmptyFile = FALSE;
  8137. char sLineWord[1600]={0};
  8138. char chargingProfiles[10][100]={0};
  8139. int ChargeProfileCount = 0;
  8140. int ch;
  8141. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8142. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8143. json_object *ClearChargingProfile;
  8144. ClearChargingProfile = json_tokener_parse(payload);
  8145. if(!is_error(ClearChargingProfile))
  8146. {
  8147. // Optional data
  8148. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8149. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8150. else
  8151. chargingProfileIdIsNULL = TRUE;
  8152. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8153. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8154. else
  8155. connectorIsNULL = TRUE;
  8156. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8157. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8158. else
  8159. chargingProfilePurposeIsNULL = TRUE;
  8160. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8161. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8162. else
  8163. stackLevelIsNULL = TRUE;
  8164. }
  8165. json_object_put(ClearChargingProfile);
  8166. if(connectorIsNULL == FALSE)
  8167. {
  8168. switch(connectorIdInt)
  8169. {
  8170. case 0:
  8171. if(chargingProfilePurposeIsNULL == TRUE)
  8172. {
  8173. int l = 0;
  8174. strcpy(fname, ChargePointMaxProfile_JSON);
  8175. if((access(fname,F_OK))!=-1)
  8176. {
  8177. strcpy(chargingProfiles[l], fname);
  8178. l = l + 1;
  8179. }
  8180. strcpy(fname, TxDefaultProfile_0_JSON);
  8181. if((access(fname,F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[l], fname);
  8184. l = l + 1;
  8185. }
  8186. ChargeProfileCount = l;
  8187. }
  8188. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8189. {
  8190. strcpy(fname, ChargePointMaxProfile_JSON);
  8191. if((access(fname,F_OK))!=-1)
  8192. {
  8193. strcpy(chargingProfiles[0], fname);
  8194. ChargeProfileCount = 1;
  8195. }
  8196. }
  8197. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8198. {
  8199. strcpy(fname, TxDefaultProfile_0_JSON);
  8200. if((access(fname,F_OK))!=-1)
  8201. {
  8202. strcpy(chargingProfiles[0], fname);
  8203. ChargeProfileCount = 1;
  8204. }
  8205. }
  8206. break;
  8207. default:
  8208. if(chargingProfilePurposeIsNULL == TRUE)
  8209. {
  8210. int m = 0;
  8211. memset(fname, 0, ARRAY_SIZE(fname));
  8212. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8213. if((access(fname,F_OK))!=-1)
  8214. {
  8215. strcpy(chargingProfiles[m], fname);
  8216. m = m + 1;
  8217. }
  8218. memset(fname, 0, ARRAY_SIZE(fname));
  8219. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8220. if((access(fname,F_OK))!=-1)
  8221. {
  8222. strcpy(chargingProfiles[m], fname);
  8223. m = m + 1;
  8224. }
  8225. ChargeProfileCount = m;
  8226. }
  8227. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8228. {
  8229. //strcpy(fname, TxDefaultProfile_1_JSON);
  8230. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8231. if((access(fname,F_OK))!=-1)
  8232. {
  8233. strcpy(chargingProfiles[0], fname);
  8234. ChargeProfileCount = 1;
  8235. }
  8236. }
  8237. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8238. {
  8239. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8240. if((access(fname,F_OK))!=-1)
  8241. {
  8242. strcpy(chargingProfiles[0], fname);
  8243. ChargeProfileCount = 1;
  8244. }
  8245. //strcpy(fname, TxProfile_1_JSON);
  8246. }
  8247. //strcpy(fname, ChargePointMaxProfile_JSON );
  8248. break;
  8249. }
  8250. }
  8251. else // Check all Charging Profiles
  8252. {
  8253. int i = 0;
  8254. char fnametemp[200]={0};
  8255. ChargeProfileCount = 0;
  8256. //Check ChargePointMaxProfile.json exit
  8257. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8258. {
  8259. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8260. i = i + 1;
  8261. }
  8262. //Check TxDefaultProfile_0.json exit
  8263. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8264. {
  8265. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8266. i = i + 1;
  8267. }
  8268. //Check TxDefaultProfile_%d.json
  8269. for(int j=1; j <= gunTotalNumber; j++)
  8270. {
  8271. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8272. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8273. if((access(fnametemp,F_OK))!=-1)
  8274. {
  8275. strcpy(chargingProfiles[i], fnametemp);
  8276. i = i + 1;
  8277. }
  8278. }
  8279. //Check TxProfile_%d.json
  8280. for(int j=1; j <= gunTotalNumber; j++)
  8281. {
  8282. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8283. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8284. if((access(fnametemp,F_OK))!=-1)
  8285. {
  8286. strcpy(chargingProfiles[i], fnametemp);
  8287. i = i + 1;
  8288. }
  8289. }
  8290. ChargeProfileCount = i;
  8291. }// End connectorIsNULL is TRUE
  8292. if(ChargeProfileCount == 0)
  8293. {
  8294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8295. goto end;
  8296. }
  8297. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8298. {
  8299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8300. goto end;
  8301. }
  8302. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8303. {
  8304. memset(str, 0, ARRAY_SIZE(str));
  8305. // clear temp file
  8306. sprintf(str,"rm -f %s",temp);
  8307. system(str);
  8308. for(int k=0; k < ChargeProfileCount; k++)
  8309. {
  8310. memset(str, 0, ARRAY_SIZE(str));
  8311. //clear file in C
  8312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8313. system(str);
  8314. }
  8315. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8316. goto end;
  8317. }
  8318. else if(connectorIsNULL == TRUE)
  8319. {
  8320. for(int k=0; k < ChargeProfileCount; k++)
  8321. {
  8322. fptr1 = fopen(chargingProfiles[k], "r");
  8323. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8324. //Check Charging Profile Count
  8325. while(fscanf(fptr1, "%s", word) != EOF)
  8326. {
  8327. //DEBUG_INFO("word=%s\n",word);
  8328. if(strstr(word, "chargingProfileId")!= NULL)
  8329. {
  8330. //DEBUG_INFO("test chargingProfileId \n");
  8331. n_chargingProfile = n_chargingProfile + 1;
  8332. //DEBUG_INFO("chargingProfileId Found\n");
  8333. }
  8334. }
  8335. rewind(fptr1);
  8336. //search Charging Profile Element
  8337. //int i= 0;
  8338. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8339. {
  8340. json_object *tmpProfilee;
  8341. tmpProfilee = json_tokener_parse(sLineWord);
  8342. if(!is_error(tmpProfilee))
  8343. {
  8344. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8345. {
  8346. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8347. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8348. }
  8349. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8350. {
  8351. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8352. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8353. }
  8354. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8355. {
  8356. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8357. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8358. }
  8359. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8360. {
  8361. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8362. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8363. }
  8364. }
  8365. json_object_put(tmpProfilee);
  8366. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8367. {
  8368. //------- not write to fptr2-------//
  8369. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8370. //clearflag = TRUE;
  8371. }
  8372. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8373. {
  8374. //------- not write to fptr2-------//
  8375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8376. }
  8377. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8378. {
  8379. //------- not write to fptr2-------//
  8380. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8381. }
  8382. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8383. {
  8384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8385. }
  8386. else
  8387. {
  8388. fprintf(fptr2, sLineWord);//writing data into file
  8389. }
  8390. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8391. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8392. if(clearflag == TRUE)
  8393. {
  8394. fclose(fptr1);
  8395. fclose(fptr2);
  8396. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8397. system(str);
  8398. // clear temp file
  8399. sprintf(str,"rm -f %s",temp);
  8400. system(str);
  8401. }
  8402. else
  8403. {
  8404. fclose(fptr1);
  8405. fclose(fptr2);
  8406. memset(str, 0, ARRAY_SIZE(str));
  8407. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8408. system(str);
  8409. resultRename = rename(temp, chargingProfiles[k]);
  8410. if(resultRename == 0)
  8411. {
  8412. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8413. }
  8414. else
  8415. {
  8416. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8417. }
  8418. if(comfirmstr[0]== 0)
  8419. {
  8420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8421. }
  8422. //Check chargingProfile is empty file
  8423. /*------ Read the file ----------------*/
  8424. fptr1=fopen(chargingProfiles[k],"r");
  8425. ch=fgetc(fptr1);
  8426. rewind(fptr1);
  8427. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8428. if(ch!=EOF)
  8429. {
  8430. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8431. {
  8432. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8433. if(sLineWord[0]=='\0')
  8434. {
  8435. isEmptyFile = TRUE;
  8436. break;
  8437. }
  8438. else
  8439. {
  8440. isEmptyFile = FALSE;
  8441. break;
  8442. }
  8443. }
  8444. }
  8445. else
  8446. isEmptyFile = TRUE;
  8447. fclose(fptr1);
  8448. if(isEmptyFile == TRUE)
  8449. {
  8450. memset(str, 0, ARRAY_SIZE(str));
  8451. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8452. system(str);
  8453. }
  8454. }
  8455. }// End of while(int k=0; k < ChargePointCount; k++)
  8456. }
  8457. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8458. {
  8459. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8460. for(int k=0; k < ChargeProfileCount; k++)
  8461. {
  8462. fptr1 = fopen(chargingProfiles[k], "r");
  8463. fptr2 = fopen(temp, "w+");
  8464. //Check Charging Profile Count
  8465. while(fscanf(fptr1, "%s", word) != EOF)
  8466. {
  8467. //DEBUG_INFO("word=%s\n",word);
  8468. if(strstr(word, "chargingProfileId")!= NULL)
  8469. {
  8470. n_chargingProfile = n_chargingProfile + 1;
  8471. }
  8472. }
  8473. rewind(fptr1);
  8474. //search Charging Profile Element
  8475. //int i= 0;
  8476. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8477. {
  8478. json_object *tmpProfilee;
  8479. tmpProfilee = json_tokener_parse(sLineWord);
  8480. if(!is_error(tmpProfilee))
  8481. {
  8482. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8483. {
  8484. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8485. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8486. }
  8487. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8488. {
  8489. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8490. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8491. }
  8492. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8493. {
  8494. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8495. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8496. }
  8497. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8498. {
  8499. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8500. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8501. }
  8502. }
  8503. json_object_put(tmpProfilee);
  8504. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8505. {
  8506. //------- not write to fptr2-------//
  8507. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8508. //clearflag = TRUE;
  8509. }
  8510. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8511. {
  8512. //------- not write to fptr2-------//
  8513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8514. }
  8515. else if(stackLevelIsNULL == TRUE)
  8516. {
  8517. //Clear Whole File
  8518. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8519. clearflag = TRUE;
  8520. break;
  8521. }
  8522. else
  8523. {
  8524. fprintf(fptr2, sLineWord);//writing data into file
  8525. }
  8526. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8527. }
  8528. if(clearflag == TRUE)
  8529. {
  8530. fclose(fptr1);
  8531. fclose(fptr2);
  8532. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8533. system(str);
  8534. // clear temp file
  8535. sprintf(str,"rm -f %s",temp);
  8536. system(str);
  8537. }
  8538. else
  8539. {
  8540. fclose(fptr1);
  8541. fclose(fptr2);
  8542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8543. system(str);
  8544. resultRename = rename(temp, chargingProfiles[k]);
  8545. if(resultRename == 0)
  8546. {
  8547. DEBUG_INFO("File ChargingProfile renamed successfully");
  8548. }
  8549. else
  8550. {
  8551. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8552. }
  8553. if(comfirmstr[0]== 0)
  8554. {
  8555. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8556. }
  8557. //Check chargingProfile is empty file
  8558. /*------ Read the file ----------------*/
  8559. fptr1=fopen(chargingProfiles[k],"r");
  8560. ch=fgetc(fptr1);
  8561. rewind(fptr1);
  8562. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8563. if(ch!=EOF)
  8564. {
  8565. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8566. {
  8567. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8568. if(sLineWord[0]=='\0')
  8569. {
  8570. isEmptyFile = TRUE;
  8571. break;
  8572. }
  8573. else
  8574. {
  8575. isEmptyFile = FALSE;
  8576. break;
  8577. }
  8578. }
  8579. }
  8580. else
  8581. isEmptyFile = TRUE;
  8582. fclose(fptr1);
  8583. if(isEmptyFile == TRUE)
  8584. {
  8585. memset(str, 0, ARRAY_SIZE(str));
  8586. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8587. system(str);
  8588. }
  8589. /*------- End of reading ---------------*/
  8590. }
  8591. } // while(int k=0; k < ChargeProfileCount; k++)
  8592. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8593. end:
  8594. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8595. {
  8596. if(connectorIdInt == 0)
  8597. {
  8598. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8599. {
  8600. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8601. }
  8602. }
  8603. else
  8604. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8605. }
  8606. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8607. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8608. return result;
  8609. }
  8610. void createFirmwareVersionByDataTransfer(void)
  8611. {
  8612. json_object *FirmwareDataTransfer = json_object_new_object();
  8613. // AC & DC model
  8614. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8615. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8616. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8617. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8618. // DC model
  8619. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8620. {
  8621. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8622. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8623. (gunType[3] != GUN_TYPE_UNKNOWN))
  8624. {
  8625. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8626. }
  8627. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8628. {
  8629. // DS DM DW
  8630. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8631. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8632. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8633. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8634. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8635. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8636. }
  8637. else
  8638. {
  8639. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8640. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8642. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8643. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8644. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8653. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8655. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8656. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8657. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8661. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8663. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8665. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8667. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8669. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8670. }
  8671. }
  8672. // 4G model
  8673. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8674. {
  8675. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8676. }
  8677. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8678. json_object_put(FirmwareDataTransfer);
  8679. }
  8680. int handleDataTransferRequest(char *uuid, char *payload)
  8681. {
  8682. mtrace();
  8683. json_object *response = json_object_new_object();
  8684. int result = FAIL;
  8685. char tempvendorId[255]={0};
  8686. char tempmessageId[50]={0};
  8687. char tempdata[512]={0};
  8688. char message[2048]={0};
  8689. DEBUG_INFO("handleDataTransferRequest...\n");
  8690. if((uuid != NULL) && (payload != NULL))
  8691. {
  8692. json_object *DataTransfer;
  8693. DataTransfer = json_tokener_parse(payload);
  8694. if(!is_error(DataTransfer))
  8695. {
  8696. // Required data
  8697. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8698. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8699. // Optional data
  8700. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8701. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8702. if(json_object_object_get(DataTransfer, "data") != NULL)
  8703. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8704. result = PASS;
  8705. }
  8706. json_object_put(DataTransfer);
  8707. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8708. {
  8709. // Send all moudle firmware version on EVSE
  8710. createFirmwareVersionByDataTransfer();
  8711. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8712. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8713. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8714. json_object_put(response);
  8715. }
  8716. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8717. {
  8718. system("/usr/bin/run_tmate_restart.sh &");
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8721. json_object_put(response);
  8722. }
  8723. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8724. {
  8725. json_object *data;
  8726. data = json_tokener_parse(tempdata);
  8727. if(!is_error(data))
  8728. {
  8729. 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))
  8730. {
  8731. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8732. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8733. if(json_object_object_get(data, "SOC") != NULL)
  8734. {
  8735. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8736. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8737. }
  8738. if(json_object_object_get(data, "Energy") != NULL)
  8739. {
  8740. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8741. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8742. }
  8743. if(json_object_object_get(data, "Duration") != NULL)
  8744. {
  8745. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8746. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8747. }
  8748. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8749. }
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8754. }
  8755. }
  8756. else
  8757. {
  8758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8759. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8760. }
  8761. json_object_put(data);
  8762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8763. json_object_put(response);
  8764. }
  8765. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8766. {
  8767. json_object *data;
  8768. data = json_tokener_parse(tempdata);
  8769. if(!is_error(data))
  8770. {
  8771. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8772. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8773. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8774. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8775. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8776. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8780. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8781. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8782. }
  8783. else
  8784. {
  8785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8786. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8787. }
  8788. json_object_put(data);
  8789. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8790. json_object_put(response);
  8791. }
  8792. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8793. {
  8794. json_object *data;
  8795. data = json_tokener_parse(tempdata);
  8796. if(!is_error(data))
  8797. {
  8798. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8799. if(json_object_object_get(data, "idToken") != NULL)
  8800. {
  8801. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8802. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8803. }
  8804. if(json_object_object_get(data, "price") != NULL)
  8805. {
  8806. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8807. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8808. }
  8809. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8810. }
  8811. else
  8812. {
  8813. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8814. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8815. }
  8816. json_object_put(data);
  8817. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8818. json_object_put(response);
  8819. }
  8820. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8821. {
  8822. json_object *data;
  8823. data = json_tokener_parse(tempdata);
  8824. if(!is_error(data))
  8825. {
  8826. if(json_object_object_get(data, "txId") != NULL)
  8827. {
  8828. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8829. for(int idx = 0;idx<gunTotalNumber;idx++)
  8830. {
  8831. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8832. {
  8833. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8834. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8835. if(json_object_object_get(data, "description") != NULL)
  8836. {
  8837. // California pricing V1.0
  8838. DEBUG_INFO("California pricing V1.0\n");
  8839. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8840. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8841. }
  8842. else
  8843. {
  8844. // California pricing V1.1
  8845. DEBUG_INFO("California pricing V1.1\n");
  8846. if(json_object_object_get(data, "timestamp") != NULL)
  8847. {
  8848. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8849. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8850. }
  8851. if(json_object_object_get(data, "meterValue") != NULL)
  8852. {
  8853. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8854. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8855. }
  8856. if(json_object_object_get(data, "cost") != NULL)
  8857. {
  8858. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8859. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8860. }
  8861. if(json_object_object_get(data, "state") != NULL)
  8862. {
  8863. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8864. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8865. }
  8866. if(json_object_object_get(data, "chargingPrice") != NULL)
  8867. {
  8868. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8869. {
  8870. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8871. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8872. }
  8873. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8874. {
  8875. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8876. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8877. }
  8878. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8879. {
  8880. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8881. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8882. }
  8883. }
  8884. if(json_object_object_get(data, "idlePrice") != NULL)
  8885. {
  8886. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8887. {
  8888. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8889. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8890. }
  8891. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8892. {
  8893. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8894. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8895. }
  8896. }
  8897. if(json_object_object_get(data, "nextPeriod") != NULL)
  8898. {
  8899. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8900. {
  8901. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8902. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8903. }
  8904. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8905. {
  8906. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8907. {
  8908. 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")));
  8909. 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"));
  8910. }
  8911. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8912. {
  8913. 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")));
  8914. 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"));
  8915. }
  8916. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8917. {
  8918. 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")));
  8919. 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"));
  8920. }
  8921. }
  8922. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8923. {
  8924. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8925. {
  8926. 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")));
  8927. 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"));
  8928. }
  8929. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8930. {
  8931. 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")));
  8932. 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"));
  8933. }
  8934. }
  8935. }
  8936. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8937. {
  8938. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8939. {
  8940. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8941. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8942. }
  8943. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8944. {
  8945. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8946. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8947. }
  8948. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8949. {
  8950. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8951. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8952. }
  8953. }
  8954. }
  8955. }
  8956. }
  8957. }
  8958. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8959. }
  8960. else
  8961. {
  8962. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8963. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8964. }
  8965. json_object_put(data);
  8966. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8967. json_object_put(response);
  8968. }
  8969. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8970. {
  8971. json_object *data;
  8972. data = json_tokener_parse(tempdata);
  8973. if(!is_error(data))
  8974. {
  8975. if(json_object_object_get(data, "txId") != NULL)
  8976. {
  8977. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8978. for(int idx = 0;idx<gunTotalNumber;idx++)
  8979. {
  8980. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8981. {
  8982. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8983. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8984. if(json_object_object_get(data, "description") != NULL)
  8985. {
  8986. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8987. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8988. }
  8989. }
  8990. }
  8991. }
  8992. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8993. }
  8994. else
  8995. {
  8996. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8997. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8998. }
  8999. json_object_put(data);
  9000. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9001. json_object_put(response);
  9002. }
  9003. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9004. {
  9005. json_object *data;
  9006. data = json_tokener_parse(tempdata);
  9007. if(!is_error(data))
  9008. {
  9009. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9010. if(json_object_object_get(data, "Content_Type") != NULL)
  9011. {
  9012. 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))
  9013. {
  9014. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9015. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9016. {
  9017. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9018. }
  9019. }
  9020. else
  9021. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9022. }
  9023. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9024. }
  9025. else
  9026. {
  9027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9028. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9029. }
  9030. json_object_put(data);
  9031. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9032. json_object_put(response);
  9033. }
  9034. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9035. {
  9036. json_object *data;
  9037. data = json_tokener_parse(tempdata);
  9038. if(!is_error(data))
  9039. {
  9040. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9041. if(json_object_object_get(data, "ConnectorId") != NULL)
  9042. {
  9043. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9044. }
  9045. if(json_object_object_get(data, "Page_Index") != NULL)
  9046. {
  9047. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9048. }
  9049. if(json_object_object_get(data, "Duration") != NULL)
  9050. {
  9051. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9052. }
  9053. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9054. }
  9055. else
  9056. {
  9057. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9058. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9059. }
  9060. json_object_put(data);
  9061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9062. json_object_put(response);
  9063. }
  9064. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9065. {
  9066. json_object *data;
  9067. data = json_tokener_parse(tempdata);
  9068. if(!is_error(data))
  9069. {
  9070. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9071. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9072. {
  9073. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9074. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9075. else
  9076. {
  9077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9078. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9079. }
  9080. }
  9081. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9082. {
  9083. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9084. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9085. else
  9086. {
  9087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9088. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9089. }
  9090. }
  9091. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9092. {
  9093. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9094. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9095. else
  9096. {
  9097. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9098. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9099. }
  9100. }
  9101. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9102. {
  9103. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9104. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9105. else
  9106. {
  9107. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9108. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9109. }
  9110. }
  9111. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9112. {
  9113. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9114. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. }
  9121. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9122. {
  9123. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9124. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9125. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9126. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9127. else
  9128. {
  9129. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9130. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9131. }
  9132. }
  9133. if(json_object_object_get(data, "isAuthentication") != NULL)
  9134. {
  9135. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9136. {
  9137. case 0:
  9138. case 1:
  9139. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9140. break;
  9141. default:
  9142. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9143. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9144. break;
  9145. }
  9146. }
  9147. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9148. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9149. }
  9150. else
  9151. {
  9152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9154. }
  9155. json_object_put(data);
  9156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9157. json_object_put(response);
  9158. }
  9159. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9160. {
  9161. json_object *data;
  9162. data = json_tokener_parse(tempdata);
  9163. if(!is_error(data))
  9164. {
  9165. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9166. if(json_object_object_get(data, "stationName") != NULL)
  9167. {
  9168. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9169. }
  9170. else
  9171. {
  9172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9173. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9174. }
  9175. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9176. {
  9177. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9178. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9179. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9180. }
  9181. }
  9182. else
  9183. {
  9184. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9185. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9186. }
  9187. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9188. json_object_put(response);
  9189. }
  9190. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9191. {
  9192. json_object *data;
  9193. data = json_tokener_parse(tempdata);
  9194. if(!is_error(data))
  9195. {
  9196. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9197. if(json_object_object_get(data, "weatherId") != NULL)
  9198. {
  9199. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9200. }
  9201. else
  9202. {
  9203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9204. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9205. }
  9206. if(json_object_object_get(data, "Temperature") != NULL)
  9207. {
  9208. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9209. }
  9210. else
  9211. {
  9212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9213. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9214. }
  9215. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9216. {
  9217. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9218. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9219. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9220. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9221. }
  9222. }
  9223. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9224. {
  9225. json_object *data;
  9226. data = json_tokener_parse(tempdata);
  9227. if(!is_error(data))
  9228. {
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9231. {
  9232. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9233. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9234. }
  9235. else
  9236. {
  9237. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9238. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9239. }
  9240. }
  9241. else
  9242. {
  9243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9244. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9245. }
  9246. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9247. json_object_put(response);
  9248. }
  9249. else
  9250. {
  9251. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9252. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9253. }
  9254. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9255. json_object_put(response);
  9256. }
  9257. else
  9258. {
  9259. // Can not find valid message id
  9260. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9261. }
  9262. }
  9263. else
  9264. {
  9265. // Payload is null
  9266. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9267. }
  9268. LWS_Send(message);
  9269. return result;
  9270. }
  9271. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9272. {
  9273. mtrace();
  9274. int result = FAIL;
  9275. int connectorIdInt, durationInt;
  9276. char chargingRateUnitStr[4]={0};
  9277. char comfirmstr[20];
  9278. int confirmPeriods = 0;
  9279. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9280. json_object *GetCompositeSchedule;
  9281. GetCompositeSchedule = json_tokener_parse(payload);
  9282. if(!is_error(GetCompositeSchedule))
  9283. {
  9284. // Required data
  9285. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9286. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9287. else
  9288. connectorIdInt = -1;
  9289. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9290. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9291. else
  9292. durationInt = 86400;
  9293. // Optional data
  9294. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9295. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9296. }
  9297. json_object_put(GetCompositeSchedule);
  9298. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9299. if((connectorIdInt == 0) ||
  9300. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9301. {
  9302. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9303. struct StructChargingProfile tmpProfile[1];
  9304. if(strstr(chargingRateUnitStr, "W") != NULL)
  9305. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9306. else
  9307. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9308. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9309. {
  9310. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9311. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9312. }
  9313. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9314. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9315. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9316. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9317. {
  9318. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9319. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9320. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9321. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9322. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9323. {
  9324. confirmPeriods = idx;
  9325. break;
  9326. }
  9327. }
  9328. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9329. {
  9330. confirmPeriods += 1;
  9331. }
  9332. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9333. }
  9334. else
  9335. {
  9336. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9337. }
  9338. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9339. return result;
  9340. }
  9341. int handleGetConfigurationRequest(char *uuid, char *payload)
  9342. {
  9343. mtrace();
  9344. int result = FAIL;
  9345. int MaxKeySupported = 0;
  9346. int n_keys = 0;
  9347. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9348. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9349. json_object *GetConfiguration;
  9350. GetConfiguration = json_tokener_parse(payload);
  9351. if(!is_error(GetConfiguration))
  9352. {
  9353. // Optional data
  9354. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9355. {
  9356. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9357. {
  9358. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9359. n_keys = idx + 1;
  9360. }
  9361. }
  9362. }
  9363. json_object_put(GetConfiguration);
  9364. UnknownKeynum = 0;
  9365. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9366. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9367. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9368. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9369. if(n_keys != 0)
  9370. {
  9371. for(int i=0;i<n_keys;i++)
  9372. {
  9373. getKeyValue(requestKey[i]);
  9374. }
  9375. }
  9376. else
  9377. {
  9378. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9379. getKeyValue("");
  9380. }
  9381. processUnkownKey();
  9382. sendGetConfigurationConfirmation(uuid);
  9383. return result;
  9384. }
  9385. static char fnamePlusPath[100]={0};
  9386. static char fnamePWithNoPath[60]={0};
  9387. void checkUploadLog(void)
  9388. {
  9389. FILE *fp;
  9390. /* Open the command for reading. */
  9391. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9392. if (fp == NULL) {
  9393. DEBUG_WARN("Failed to run command\n" );
  9394. exit(1);
  9395. }
  9396. int ftppathlen = 0;
  9397. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9398. int i = 0;
  9399. /* Read the output a line at a time - output it. */
  9400. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9401. if(i==0)
  9402. {
  9403. ftppathlen = strlen(fnamePlusPath);
  9404. DEBUG_INFO("%s\n", fnamePlusPath);
  9405. fnamePlusPath[ftppathlen]='\0';
  9406. break;
  9407. }
  9408. i= i+1;
  9409. }
  9410. /* close */
  9411. pclose(fp);
  9412. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9413. {
  9414. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9415. {
  9416. fnamePlusPath[k]='\0';
  9417. }
  9418. }
  9419. i=1;
  9420. //char fname[60]={0};
  9421. while(i < ftppathlen)
  9422. {
  9423. int len=ftppathlen-i;
  9424. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9425. {
  9426. DEBUG_INFO("compare '/' all right\n");
  9427. break;
  9428. }
  9429. i=i+1;
  9430. }
  9431. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9432. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9433. fnamePWithNoPath[i+1] = '\0';
  9434. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9435. {
  9436. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9437. {
  9438. fnamePWithNoPath[j]='\0';
  9439. }
  9440. }
  9441. FILE* fp1 = fopen(fnamePlusPath, "r");
  9442. if (fp1)
  9443. {
  9444. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9445. // file exists
  9446. fclose(fp1);
  9447. }
  9448. else
  9449. {
  9450. // file doesn't exist
  9451. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9452. }
  9453. }
  9454. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9455. {
  9456. mtrace();
  9457. int result = FAIL;
  9458. time_t CurrentTime;
  9459. struct tm *tm;
  9460. pthread_t th_Status;
  9461. CurrentTime = time(NULL);
  9462. tm = localtime(&CurrentTime);
  9463. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9464. 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);
  9465. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9466. if(!interLock.isGetDiagnosticGoing)
  9467. {
  9468. interLock.isGetDiagnosticGoing = 1;
  9469. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9470. sleep(1);
  9471. }
  9472. else
  9473. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9474. return result;
  9475. }
  9476. void* GetDiagnosticsProcess(void* data)
  9477. {
  9478. pthread_detach(pthread_self());
  9479. mtrace();
  9480. int retriesInt=0, retryIntervalInt=0;
  9481. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9482. 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};
  9483. int port=0;
  9484. int isSuccess = FALSE;
  9485. char ftpbuf[200]={0};
  9486. char cmdBuf[2048];
  9487. struct tm *tmNow;
  9488. time_t CurrentTime;
  9489. struct tm tmStart;
  9490. struct tm tmStop;
  9491. CurrentTime = time(NULL);
  9492. tmNow=localtime(&CurrentTime);
  9493. uint16_t targetYear, targetMonth;
  9494. json_object *GetDiagnostics;
  9495. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9496. GetDiagnostics = json_tokener_parse(data);
  9497. if(!is_error(GetDiagnostics))
  9498. {
  9499. // Required data
  9500. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9501. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9502. // Optional data
  9503. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9504. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9505. else
  9506. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9507. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9508. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9509. else
  9510. retryIntervalInt = 30;
  9511. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9512. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9513. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9514. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9515. }
  9516. json_object_put(GetDiagnostics);
  9517. // Pack log to compress file
  9518. 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) &&
  9519. (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))
  9520. {
  9521. // Pack system log
  9522. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9523. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9524. targetYear = tmStart.tm_year;
  9525. targetMonth = tmStart.tm_mon;
  9526. do
  9527. {
  9528. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9529. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9530. if(targetMonth+1>=13)
  9531. {
  9532. targetYear += 1;
  9533. targetMonth = 1;
  9534. }
  9535. else
  9536. {
  9537. targetMonth += 1;
  9538. }
  9539. }while((targetYear < (tmNow->tm_year+1900)) ||
  9540. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9541. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9542. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9543. system(cmdBuf);
  9544. // Pack charging & event log
  9545. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9546. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9547. targetYear = tmStart.tm_year;
  9548. targetMonth = tmStart.tm_mon;
  9549. do
  9550. {
  9551. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9552. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9553. if(targetMonth+1>=13)
  9554. {
  9555. targetYear += 1;
  9556. targetMonth = 1;
  9557. }
  9558. else
  9559. {
  9560. targetMonth += 1;
  9561. }
  9562. }while((targetYear < (tmNow->tm_year+1900)) ||
  9563. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9564. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9565. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9566. system(cmdBuf);
  9567. // Combine log file
  9568. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9569. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9570. }
  9571. else
  9572. {
  9573. system("exec /root/logPackTools 'log' 6");
  9574. }
  9575. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9576. system(cmdBuf);
  9577. checkUploadLog();
  9578. //****************location*******************/
  9579. if(strcmp(locationstr,"")==0)
  9580. {
  9581. DEBUG_INFO("location is <Empty>!\n");
  9582. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9583. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9584. goto end;
  9585. }
  9586. memset(protocol, 0, ARRAY_SIZE(protocol));
  9587. memset(user, 0, ARRAY_SIZE(user) );
  9588. memset(password, 0, ARRAY_SIZE(password));
  9589. memset(host, 0, ARRAY_SIZE(host));
  9590. memset(path, 0, ARRAY_SIZE(path));
  9591. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9592. memset(host1, 0, ARRAY_SIZE(host1));
  9593. memset(path1, 0, ARRAY_SIZE(path1));
  9594. /*location: ftp://user:password@host:port/path*/
  9595. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9596. if((access(fnamePlusPath,F_OK))!=-1)
  9597. {
  9598. DEBUG_INFO("fnamePlusPath exist.\n");
  9599. }
  9600. else
  9601. {
  9602. DEBUG_INFO("fnamePlusPath not exist!\n");
  9603. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9604. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9605. goto end;
  9606. }
  9607. if(strchr(locationstr,'@')==NULL)
  9608. {
  9609. sscanf(locationstr,
  9610. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9611. protocol, host, &port, path);
  9612. strcpy(user,"anonymous");
  9613. strcpy(password,"");
  9614. }
  9615. else
  9616. {
  9617. //DEBUG_INFO("pch=%s\n", pch);
  9618. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9619. protocol, user, password, host, &port, path);
  9620. }
  9621. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9622. {
  9623. DEBUG_INFO("protocol is not ftp/http ! \n");
  9624. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9625. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9626. goto end;
  9627. }
  9628. if(strncmp(locationstr,"http", 4) == 0)
  9629. {
  9630. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9631. sprintf(ftppath,"/%s", path);
  9632. do
  9633. {
  9634. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9635. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9636. sleep(3);
  9637. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9638. if(!isSuccess)
  9639. {
  9640. DEBUG_INFO("Diagnostics fail.\n");
  9641. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9642. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9643. sleep(retryIntervalInt);
  9644. }
  9645. else
  9646. {
  9647. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9648. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9649. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9650. }
  9651. retriesInt--;
  9652. }while((isSuccess == 0)&&(retriesInt >= 0));
  9653. }
  9654. else
  9655. {
  9656. sscanf(host,"%[^/]%s",host1, path1);
  9657. if(strlen(path) > 0)
  9658. sprintf(ftppath,"/%s", path);
  9659. else
  9660. sprintf(ftppath,"/%s", path1);
  9661. int ftppathlen=strlen(ftppath);
  9662. int i=1;
  9663. char filenametemp[50];
  9664. while(i < ftppathlen)
  9665. {
  9666. int len=ftppathlen-i;
  9667. if(ftppath[len]== 47) // '/' ascll code: 47
  9668. {
  9669. DEBUG_INFO("find '/' all right\n");
  9670. break;
  9671. }
  9672. i=i+1;
  9673. }
  9674. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9675. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9676. filenametemp[i+1] = 0;
  9677. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9678. if(port == 0)
  9679. port = 21;
  9680. do
  9681. {
  9682. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9683. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9684. sleep(3);
  9685. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9686. if(!isSuccess)
  9687. {
  9688. DEBUG_INFO("Diagnostics fail.\n");
  9689. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9690. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9691. sleep(retryIntervalInt);
  9692. }
  9693. else
  9694. {
  9695. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9696. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9697. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9698. }
  9699. retriesInt--;
  9700. }while((!isSuccess)&&(retriesInt >= 0));
  9701. }
  9702. end:
  9703. system("rm -f /mnt/*");
  9704. sleep(5);
  9705. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9706. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9707. interLock.isGetDiagnosticGoing = 0;
  9708. pthread_exit(NULL);
  9709. }
  9710. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9711. {
  9712. mtrace();
  9713. int result = FAIL;
  9714. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9715. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9716. {
  9717. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9718. locallistVersion = -1;
  9719. }
  9720. else
  9721. {
  9722. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9723. OCPP_getListVerion();
  9724. }
  9725. //from db.OCPP_getListVerion
  9726. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9727. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9728. sendGetLocalListVersionConfirmation(uuid,"");
  9729. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9730. return result;
  9731. }
  9732. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9733. {
  9734. mtrace();
  9735. int result = FAIL;
  9736. int connectorIdInt=-1;
  9737. int tempIndex = 0;
  9738. int connectorIdIsNULL, chargingProfileIsNULL;
  9739. char comfirmstr[20]={0};
  9740. char cmdBuf[512];
  9741. json_object *RemoteStartTransaction;
  9742. FILE *fp;
  9743. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9744. if(server_pending == TRUE)
  9745. {
  9746. return 0;
  9747. }
  9748. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9749. RemoteStartTransaction = json_tokener_parse(payload);
  9750. if(!is_error(RemoteStartTransaction))
  9751. {
  9752. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9753. {
  9754. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9755. }
  9756. else
  9757. {
  9758. connectorIdIsNULL = TRUE;
  9759. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9760. {
  9761. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9762. {
  9763. connectorIdIsNULL = FALSE;
  9764. connectorIdInt = (gun_index+1);
  9765. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9766. break;
  9767. }
  9768. }
  9769. }
  9770. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9771. {
  9772. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9773. // Required data
  9774. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9775. // Optional data
  9776. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9777. {
  9778. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9779. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9780. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9781. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9782. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9783. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9784. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9785. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9786. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9787. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9788. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9789. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9790. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9791. {
  9792. 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")));
  9793. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9794. 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"));
  9795. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9796. 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"));
  9797. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9798. 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")));
  9799. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9800. {
  9801. 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++)
  9802. {
  9803. 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"));
  9804. 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"));
  9805. 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)
  9806. 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"));
  9807. }
  9808. }
  9809. }
  9810. }
  9811. else
  9812. {
  9813. chargingProfileIsNULL = TRUE;
  9814. }
  9815. }
  9816. }
  9817. else
  9818. {
  9819. connectorIdIsNULL = TRUE;
  9820. }
  9821. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9822. {
  9823. DEBUG_WARN("Connector id is NULL\n.");
  9824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9825. goto end;
  9826. }
  9827. /*
  9828. enum _SYSTEM_STATUS
  9829. {
  9830. S_BOOTING = 0,
  9831. S_IDLE, = 1
  9832. S_AUTHORIZING, = 2
  9833. S_REASSIGN_CHECK, = 3
  9834. S_REASSIGN, = 4
  9835. S_PRECHARGE, = 5
  9836. S_PREPARING_FOR_EV, = 6
  9837. S_PREPARING_FOR_EVSE, = 7
  9838. S_CHARGING, = 8
  9839. S_TERMINATING, = 9
  9840. S_COMPLETE, = 10
  9841. S_ALARM, = 11
  9842. S_FAULT = 12
  9843. }
  9844. */
  9845. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9846. {
  9847. //check Transaction active
  9848. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9849. {
  9850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9851. {
  9852. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9853. }
  9854. else
  9855. {
  9856. tempIndex = connectorIdInt -1;
  9857. }
  9858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9859. {
  9860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9861. {
  9862. 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))
  9863. {
  9864. //Reserved
  9865. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9866. }
  9867. 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))
  9868. {
  9869. //Reserved
  9870. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9871. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9872. goto end;
  9873. }
  9874. else
  9875. {
  9876. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9877. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9878. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9879. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9880. {
  9881. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9883. goto end;
  9884. }
  9885. }//END FOR ELSE
  9886. }
  9887. }// END FOR CHAdeMO_QUANTITY
  9888. }
  9889. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9890. {
  9891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9892. {
  9893. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9894. }
  9895. else
  9896. {
  9897. tempIndex = connectorIdInt -1;
  9898. }
  9899. for (int index = 0; index < CCS_QUANTITY; index++)
  9900. {
  9901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9902. {
  9903. 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))
  9904. {
  9905. //Reserved
  9906. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9907. }
  9908. 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))
  9909. {
  9910. //Reserved
  9911. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9913. goto end;
  9914. }
  9915. else
  9916. {
  9917. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9918. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9919. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9920. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9921. {
  9922. DEBUG_WARN("CCS connector not allow start\n.");
  9923. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9924. goto end;
  9925. }
  9926. }// END FOR ELSE
  9927. }
  9928. }// END FOR CCS_QUANTITY
  9929. }
  9930. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9931. {
  9932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9933. {
  9934. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9935. }
  9936. else
  9937. {
  9938. tempIndex = connectorIdInt -1;
  9939. }
  9940. for (int index = 0; index < GB_QUANTITY; index++)
  9941. {
  9942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9943. {
  9944. 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))
  9945. {
  9946. //Reserved
  9947. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9948. }
  9949. 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))
  9950. {
  9951. //Reserved
  9952. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9953. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9954. goto end;
  9955. }
  9956. else
  9957. {
  9958. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9959. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9960. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9961. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9962. {
  9963. DEBUG_WARN("GB connector not allow start\n.");
  9964. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9965. goto end;
  9966. }
  9967. }// END FOR ELSE
  9968. }
  9969. } // END FOR GB_QUANTITY
  9970. }
  9971. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9972. {
  9973. tempIndex = connectorIdInt -1;
  9974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9975. {
  9976. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9977. {
  9978. 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))
  9979. {
  9980. //Reserved
  9981. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9982. }
  9983. 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))
  9984. {
  9985. //Reserved
  9986. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9987. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9988. goto end;
  9989. }
  9990. else
  9991. {
  9992. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9993. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9994. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9995. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9996. {
  9997. DEBUG_WARN("GB connector not allow start\n.");
  9998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9999. goto end;
  10000. }
  10001. }// END FOR ELSE
  10002. }
  10003. } // END FOR GB_QUANTITY
  10004. }
  10005. else
  10006. {
  10007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10008. {
  10009. tempIndex = 2;
  10010. }
  10011. else
  10012. {
  10013. tempIndex = connectorIdInt -1;
  10014. }
  10015. for (int index = 0; index < AC_QUANTITY; index++)
  10016. {
  10017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10018. {
  10019. 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))
  10020. {
  10021. //Reserved
  10022. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10023. }
  10024. 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))
  10025. {
  10026. //Reserved
  10027. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10028. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10029. goto end;
  10030. }
  10031. else
  10032. {
  10033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10034. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10035. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10036. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10037. {
  10038. DEBUG_WARN("AC connector not allow start\n.");
  10039. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10040. goto end;
  10041. }
  10042. }//END FOR ELSE
  10043. }
  10044. }// END FOR AC_QUANTITY
  10045. }
  10046. if(chargingProfileIsNULL == FALSE)
  10047. {
  10048. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10049. {
  10050. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10051. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10052. //memset idTag
  10053. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10054. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10055. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10057. // Save profile to file
  10058. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10059. system(cmdBuf);
  10060. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10061. fp = fopen(cmdBuf, "w");
  10062. 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));
  10063. fclose(fp);
  10064. }
  10065. else
  10066. {
  10067. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10068. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10069. }
  10070. }
  10071. else
  10072. {
  10073. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10075. //memset idTag
  10076. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10077. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10078. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10080. }
  10081. }
  10082. else
  10083. {
  10084. DEBUG_WARN("Connector id over\n.");
  10085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10086. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10087. }
  10088. end:
  10089. json_object_put(RemoteStartTransaction);
  10090. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10091. {
  10092. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10093. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10094. }
  10095. //OCPP send RemoteStartConfirmation by first.
  10096. sendRemoteStartConfirmation(uuid, comfirmstr);
  10097. return result;
  10098. }
  10099. int handleRemoteStartRequest(char *uuid, char *payload)
  10100. {
  10101. mtrace();
  10102. int result = PASS;
  10103. int connectorIdInt=-1;
  10104. int tempIndex = 0;
  10105. char comfirmstr[20]={0};
  10106. char cmdBuf[512];
  10107. json_object *RemoteStartTransaction;
  10108. FILE *fp;
  10109. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10110. if(server_pending == TRUE)
  10111. {
  10112. result = FAIL;
  10113. }
  10114. RemoteStartTransaction = json_tokener_parse(payload);
  10115. if(!is_error(RemoteStartTransaction))
  10116. {
  10117. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10118. {
  10119. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10120. }
  10121. else
  10122. {
  10123. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10124. {
  10125. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10126. {
  10127. connectorIdInt = (gun_index+1);
  10128. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10129. break;
  10130. }
  10131. }
  10132. }
  10133. if(connectorIdInt == 0)
  10134. {
  10135. DEBUG_WARN("Connector id shall not equal 0.\n");
  10136. result = FAIL;
  10137. }
  10138. else if(connectorIdInt == -1)
  10139. {
  10140. DEBUG_INFO("Connector id does not specific.\n");
  10141. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10142. {
  10143. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10144. // Required data
  10145. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10146. // Optional data
  10147. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10148. {
  10149. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10150. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10151. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10152. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10153. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10154. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10155. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10156. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10157. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10158. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10159. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10160. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10161. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10162. {
  10163. 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")));
  10164. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10165. 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"));
  10166. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10167. 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"));
  10168. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10169. 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")));
  10170. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10171. {
  10172. 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++)
  10173. {
  10174. 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"));
  10175. 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"));
  10176. 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)
  10177. 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"));
  10178. }
  10179. }
  10180. }
  10181. }
  10182. else
  10183. {
  10184. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10185. }
  10186. }
  10187. }
  10188. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10189. {
  10190. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10191. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10192. // Required data
  10193. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10194. // Optional data
  10195. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10196. {
  10197. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10198. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10199. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10200. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10201. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10202. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10203. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10204. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10205. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10206. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10207. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10208. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10209. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10210. {
  10211. 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")));
  10212. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10213. 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"));
  10214. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10215. 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"));
  10216. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10217. 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")));
  10218. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10219. {
  10220. 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++)
  10221. {
  10222. 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"));
  10223. 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"));
  10224. 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)
  10225. 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"));
  10226. }
  10227. }
  10228. }
  10229. }
  10230. else
  10231. {
  10232. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10233. }
  10234. }
  10235. else
  10236. {
  10237. DEBUG_WARN("Connector id is over maximun value.\n");
  10238. result = FAIL;
  10239. }
  10240. }
  10241. if(result == PASS)
  10242. {
  10243. if(connectorIdInt > 0)
  10244. {
  10245. //check Transaction active
  10246. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10247. {
  10248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10249. {
  10250. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10251. }
  10252. else
  10253. {
  10254. tempIndex = connectorIdInt -1;
  10255. }
  10256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10257. {
  10258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10259. {
  10260. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10263. {
  10264. //Reserved
  10265. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10266. }
  10267. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10269. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10270. {
  10271. //Reserved
  10272. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10274. goto end;
  10275. }
  10276. else
  10277. {
  10278. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10279. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10280. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10281. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10282. {
  10283. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10284. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10285. goto end;
  10286. }
  10287. }//END FOR ELSE
  10288. }
  10289. }// END FOR CHAdeMO_QUANTITY
  10290. }
  10291. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10292. {
  10293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10294. {
  10295. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10296. }
  10297. else
  10298. {
  10299. tempIndex = connectorIdInt -1;
  10300. }
  10301. for (int index = 0; index < CCS_QUANTITY; index++)
  10302. {
  10303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10304. {
  10305. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10308. {
  10309. //Reserved
  10310. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10311. }
  10312. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10313. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10314. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10315. {
  10316. //Reserved
  10317. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10318. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10319. goto end;
  10320. }
  10321. else
  10322. {
  10323. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10324. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10325. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10326. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10327. {
  10328. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10330. goto end;
  10331. }
  10332. }// END FOR ELSE
  10333. }
  10334. }// END FOR CCS_QUANTITY
  10335. }
  10336. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10337. {
  10338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10339. {
  10340. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10341. }
  10342. else
  10343. {
  10344. tempIndex = connectorIdInt -1;
  10345. }
  10346. for (int index = 0; index < GB_QUANTITY; index++)
  10347. {
  10348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10349. {
  10350. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10353. {
  10354. //Reserved
  10355. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10356. }
  10357. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10358. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10359. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10360. {
  10361. //Reserved
  10362. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10364. goto end;
  10365. }
  10366. else
  10367. {
  10368. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10369. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10370. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10371. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10372. {
  10373. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10374. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10375. goto end;
  10376. }
  10377. }// END FOR ELSE
  10378. }
  10379. } // END FOR GB_QUANTITY
  10380. }
  10381. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10382. {
  10383. tempIndex = connectorIdInt -1;
  10384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10385. {
  10386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10387. {
  10388. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10391. {
  10392. //Reserved
  10393. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10394. }
  10395. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10396. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10397. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10398. {
  10399. //Reserved
  10400. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10402. goto end;
  10403. }
  10404. else
  10405. {
  10406. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10407. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10408. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10409. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10410. {
  10411. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. }// END FOR ELSE
  10416. }
  10417. } // END FOR GB_QUANTITY
  10418. }
  10419. else
  10420. {
  10421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10422. {
  10423. tempIndex = 2;
  10424. }
  10425. else
  10426. {
  10427. tempIndex = connectorIdInt -1;
  10428. }
  10429. for (int index = 0; index < AC_QUANTITY; index++)
  10430. {
  10431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10432. {
  10433. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10439. }
  10440. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10441. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10442. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10443. {
  10444. //Reserved
  10445. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10447. goto end;
  10448. }
  10449. else
  10450. {
  10451. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10452. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10453. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10454. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10455. {
  10456. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10458. goto end;
  10459. }
  10460. }//END FOR ELSE
  10461. }
  10462. }// END FOR AC_QUANTITY
  10463. }
  10464. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10465. {
  10466. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10467. {
  10468. // Save profile to file
  10469. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10470. system(cmdBuf);
  10471. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10472. fp = fopen(cmdBuf, "w");
  10473. 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));
  10474. fclose(fp);
  10475. }
  10476. else
  10477. {
  10478. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10480. goto end;
  10481. }
  10482. }
  10483. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10485. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10486. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10487. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10489. }
  10490. else
  10491. {
  10492. uint8_t isHasIdleConnector = FALSE;
  10493. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10494. {
  10495. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10496. {
  10497. isHasIdleConnector = TRUE;
  10498. break;
  10499. }
  10500. }
  10501. if(isHasIdleConnector == TRUE)
  10502. {
  10503. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10504. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10505. {
  10506. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10507. {
  10508. // Save profile to file
  10509. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10510. system(cmdBuf);
  10511. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10512. fp = fopen(cmdBuf, "w");
  10513. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10514. fclose(fp);
  10515. refreshStartTimer(&clientTime.RemoteStartWait);
  10516. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10518. }
  10519. else
  10520. {
  10521. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10523. }
  10524. }
  10525. else
  10526. {
  10527. refreshStartTimer(&clientTime.RemoteStartWait);
  10528. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10530. }
  10531. }
  10532. else
  10533. {
  10534. DEBUG_INFO("There is not any connector is idle.\n");
  10535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10536. }
  10537. }
  10538. }
  10539. else
  10540. {
  10541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10542. }
  10543. end:
  10544. json_object_put(RemoteStartTransaction);
  10545. sendRemoteStartConfirmation(uuid, comfirmstr);
  10546. return result;
  10547. }
  10548. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10549. {
  10550. mtrace();
  10551. int result = FAIL;
  10552. int match = FALSE;
  10553. int GunNO = 0;
  10554. int tempIndex = 0;
  10555. int transactionIdInt=0;
  10556. int transactionIdIsNULL= TRUE;
  10557. char comfirmstr[20];
  10558. json_object *RemoteStopTransaction;
  10559. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10560. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10561. if(server_pending == TRUE)
  10562. {
  10563. return 0;
  10564. }
  10565. RemoteStopTransaction = json_tokener_parse(payload);
  10566. if(!is_error(RemoteStopTransaction))
  10567. {
  10568. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10569. {
  10570. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10571. transactionIdIsNULL = FALSE;
  10572. }
  10573. }
  10574. json_object_put(RemoteStopTransaction);
  10575. if(transactionIdIsNULL == FALSE)
  10576. {
  10577. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10578. {
  10579. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10580. {
  10581. //check Transaction active
  10582. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10583. {
  10584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10585. {
  10586. tempIndex = ((gun_index==2) ? 1: 0);
  10587. }
  10588. else
  10589. {
  10590. tempIndex = gun_index;
  10591. }
  10592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10593. {
  10594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10595. {
  10596. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10597. {
  10598. match = TRUE;
  10599. GunNO = gun_index;
  10600. }
  10601. }
  10602. }// END FOR CHAdeMO_QUANTITY
  10603. }
  10604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10605. {
  10606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10607. {
  10608. tempIndex = ((gun_index==2) ? 1: 0);
  10609. }
  10610. else
  10611. {
  10612. tempIndex = gun_index;
  10613. }
  10614. for (int index = 0; index < CCS_QUANTITY; index++)
  10615. {
  10616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10617. {
  10618. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10619. {
  10620. match = TRUE;
  10621. GunNO = gun_index;
  10622. }
  10623. }
  10624. }// END FOR CCS_QUANTITY
  10625. }
  10626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10627. {
  10628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10629. {
  10630. tempIndex = ((gun_index==2) ? 1: 0);
  10631. }
  10632. else
  10633. {
  10634. tempIndex = gun_index;
  10635. }
  10636. for (int index = 0; index < GB_QUANTITY; index++)
  10637. {
  10638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10639. {
  10640. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10641. {
  10642. match = TRUE;
  10643. GunNO = gun_index;
  10644. }
  10645. }
  10646. }// END FOR GB_QUANTITY
  10647. }
  10648. else if(gunType[gun_index] == GUN_TYPE_DO)
  10649. {
  10650. tempIndex = gun_index;
  10651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10652. {
  10653. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10654. {
  10655. 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
  10656. {
  10657. match = TRUE;
  10658. GunNO = gun_index;
  10659. }
  10660. }
  10661. }// END FOR GB_QUANTITY
  10662. }
  10663. else
  10664. {
  10665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10666. {
  10667. tempIndex = 2;
  10668. }
  10669. else
  10670. {
  10671. tempIndex = gun_index;
  10672. }
  10673. for (int index = 0; index < AC_QUANTITY; index++)
  10674. {
  10675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10676. {
  10677. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10678. {
  10679. match = TRUE;
  10680. GunNO = gun_index;
  10681. }
  10682. }
  10683. }// END FOR CHAdeMO_QUANTITY
  10684. } // END FOR AC ELSE
  10685. }// CHECK IF ResponseTransactionId == transactionIdInt
  10686. }//END FOR
  10687. if( match == TRUE)
  10688. {
  10689. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10691. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10692. }
  10693. else
  10694. {
  10695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10696. }
  10697. }
  10698. else
  10699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10700. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10701. return result;
  10702. }
  10703. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10704. {
  10705. mtrace();
  10706. int result = FAIL;
  10707. int connectorIdInt=0, reservationIdInt=0;
  10708. int tempIndex = 0;
  10709. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10710. char comfirmstr[20]={0};
  10711. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10712. int c = 0;
  10713. char *loc;
  10714. //char *ptr;
  10715. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10716. strcpy(sstrtemp, stringtrimspace(payload));
  10717. //***(1)connectorId ****/
  10718. c=0;
  10719. loc = strstr(sstrtemp, "connectorId");
  10720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10721. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10722. {
  10723. sstr[c] = loc[strlen("connectorId")+2+c];
  10724. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10725. c++;
  10726. }
  10727. sstr[c] = '\0';
  10728. connectorIdInt = atoi(sstr);
  10729. //***(2)expiryDate ****/
  10730. loc = strstr(sstrtemp, "expiryDate");
  10731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10732. c = 0;
  10733. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10734. {
  10735. sstr[c] = loc[3+strlen("expiryDate")+c];
  10736. c++;
  10737. }
  10738. sstr[c] = '\0';
  10739. strcpy(expiryDatestr, sstr);
  10740. //***(3)idTag ****/
  10741. loc = strstr(sstrtemp, "idTag");
  10742. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10743. c = 0;
  10744. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10745. {
  10746. sstr[c] = loc[3+strlen("idTag")+c];
  10747. c++;
  10748. }
  10749. sstr[c] = '\0';
  10750. strcpy(idTagstr, sstr);
  10751. //***(4)parentIdTag ****/
  10752. loc = strstr(sstrtemp, "parentIdTag");
  10753. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10754. c = 0;
  10755. if(loc == NULL)
  10756. {
  10757. strcpy(parentIdTagstr, "");
  10758. }
  10759. else
  10760. {
  10761. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10762. {
  10763. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10764. c++;
  10765. }
  10766. sstr[c] = '\0';
  10767. strcpy(parentIdTagstr, sstr);
  10768. }
  10769. //***(5)reservationId ****/
  10770. c=0;
  10771. loc = strstr(sstrtemp, "reservationId");
  10772. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10773. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10774. {
  10775. sstr[c] = loc[strlen("reservationId")+2+c];
  10776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10777. c++;
  10778. }
  10779. sstr[c] = '\0';
  10780. reservationIdInt = atoi(sstr);
  10781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10782. /*
  10783. enum SYSTEM_STATUS
  10784. {
  10785. SYS_MODE_BOOTING = 0,
  10786. SYS_MODE_IDLE = 1,
  10787. SYS_MODE_AUTHORIZING = 2,
  10788. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10789. SYS_MODE_REASSIGN = 4,
  10790. SYS_MODE_PREPARING = 5,
  10791. SYS_MODE_PREPARE_FOR_EV = 6,
  10792. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10793. SYS_MODE_CHARGING = 8,
  10794. SYS_MODE_TERMINATING = 9,
  10795. SYS_MODE_COMPLETE = 10,
  10796. SYS_MODE_ALARM = 11,
  10797. SYS_MODE_FAULT = 12,
  10798. SYS_MODE_RESERVATION = 13,
  10799. SYS_MODE_BOOKING = 14,
  10800. SYS_MODE_MAINTAIN = 15,
  10801. SYS_MODE_DEBUG = 16,
  10802. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10803. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10804. SYS_MODE_UPDATE = 19
  10805. };
  10806. */
  10807. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10808. {
  10809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10810. goto end;
  10811. }
  10812. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10813. {
  10814. //check Transaction active
  10815. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10816. {
  10817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10818. {
  10819. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10820. }
  10821. else
  10822. {
  10823. tempIndex = connectorIdInt -1;
  10824. }
  10825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10826. {
  10827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10828. {
  10829. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10830. {
  10831. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10832. {
  10833. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10834. {
  10835. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10837. }
  10838. 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'))
  10839. {
  10840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10841. }
  10842. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10843. {
  10844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10845. }
  10846. else
  10847. {
  10848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10849. }
  10850. }
  10851. 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
  10852. {
  10853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10854. }
  10855. }
  10856. else
  10857. {
  10858. //replace reservation
  10859. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10861. }
  10862. }
  10863. } // END FOR CHAdeMO_QUANTITY
  10864. }
  10865. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10866. {
  10867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10868. {
  10869. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10870. }
  10871. else
  10872. {
  10873. tempIndex = connectorIdInt -1;
  10874. }
  10875. for (int index = 0; index < CCS_QUANTITY; index++)
  10876. {
  10877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10878. {
  10879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10880. {
  10881. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10882. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10883. {
  10884. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10885. {
  10886. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10888. }
  10889. 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'))
  10890. {
  10891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10892. }
  10893. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10894. {
  10895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10896. }
  10897. else
  10898. {
  10899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10900. }
  10901. }
  10902. 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
  10903. {
  10904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10905. }
  10906. }
  10907. else
  10908. {
  10909. //replace reservation
  10910. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10912. }
  10913. }
  10914. } // END FOR CCS_QUANTITY
  10915. }
  10916. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10917. {
  10918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10919. {
  10920. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10921. }
  10922. else
  10923. {
  10924. tempIndex = connectorIdInt -1;
  10925. }
  10926. for (int index = 0; index < GB_QUANTITY; index++)
  10927. {
  10928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10929. {
  10930. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10931. {
  10932. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10933. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10934. {
  10935. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10936. {
  10937. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10939. }
  10940. 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'))
  10941. {
  10942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10943. }
  10944. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10945. {
  10946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10947. }
  10948. else
  10949. {
  10950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10951. }
  10952. }
  10953. 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
  10954. {
  10955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10956. }
  10957. }
  10958. else
  10959. {
  10960. //replace reservation
  10961. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10963. }
  10964. }
  10965. }// END FOR GB_QUANTITY
  10966. }
  10967. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10968. {
  10969. tempIndex = connectorIdInt -1;
  10970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10971. {
  10972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10973. {
  10974. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10975. {
  10976. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10977. 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
  10978. {
  10979. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10980. {
  10981. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10983. }
  10984. 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'))
  10985. {
  10986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10987. }
  10988. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10989. {
  10990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10991. }
  10992. else
  10993. {
  10994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10995. }
  10996. }
  10997. 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
  10998. {
  10999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11000. }
  11001. }
  11002. else
  11003. {
  11004. //replace reservation
  11005. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11007. }
  11008. }
  11009. }// END FOR GB_QUANTITY
  11010. }
  11011. else
  11012. {
  11013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11014. {
  11015. tempIndex = 2;
  11016. }
  11017. else
  11018. {
  11019. tempIndex = (connectorIdInt -1);
  11020. }
  11021. for (int index = 0; index < AC_QUANTITY; index++)
  11022. {
  11023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11024. {
  11025. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11026. {
  11027. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11028. {
  11029. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11030. {
  11031. 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))
  11032. {
  11033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11034. }
  11035. else
  11036. {
  11037. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11039. }
  11040. }
  11041. 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'))
  11042. {
  11043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11044. }
  11045. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11046. {
  11047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11048. }
  11049. else
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11052. }
  11053. }
  11054. 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
  11055. {
  11056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11057. }
  11058. }
  11059. else
  11060. {
  11061. //replace reservation
  11062. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11064. }
  11065. }
  11066. } // END FOR AC_QUANTITY
  11067. }
  11068. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11069. }
  11070. else if(connectorIdInt == 0)
  11071. {
  11072. //check Transaction active
  11073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11074. {
  11075. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11076. {
  11077. 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'))
  11078. {
  11079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11080. goto end;
  11081. }
  11082. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11083. {
  11084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11085. goto end;
  11086. }
  11087. 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
  11088. {
  11089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11090. goto end;
  11091. }
  11092. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11093. {
  11094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11095. goto end;
  11096. }
  11097. }
  11098. }// END FOR CHAdeMO_QUANTITY
  11099. for (int index = 0; index < CCS_QUANTITY; index++)
  11100. {
  11101. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11102. {
  11103. 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'))
  11104. {
  11105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11106. goto end;
  11107. }
  11108. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11109. {
  11110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11111. goto end;
  11112. }
  11113. 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
  11114. {
  11115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11116. goto end;
  11117. }
  11118. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11119. {
  11120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11121. goto end;
  11122. }
  11123. }
  11124. } // END FOR CCS_QUANTITY
  11125. for (int index = 0; index < GB_QUANTITY; index++)
  11126. {
  11127. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11128. {
  11129. 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'))
  11130. {
  11131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11132. goto end;
  11133. }
  11134. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11135. {
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11137. goto end;
  11138. }
  11139. 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
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11142. goto end;
  11143. }
  11144. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11145. {
  11146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11147. goto end;
  11148. }
  11149. }
  11150. } // END FOR GB_QUANTITY
  11151. for (int index = 0; index < AC_QUANTITY; index++)
  11152. {
  11153. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11154. {
  11155. 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'))
  11156. {
  11157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11158. goto end;
  11159. }
  11160. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11161. {
  11162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11163. goto end;
  11164. }
  11165. 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
  11166. {
  11167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11168. goto end;
  11169. }
  11170. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11171. {
  11172. 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))
  11173. {
  11174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11175. goto end;
  11176. }
  11177. }
  11178. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11179. {
  11180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11181. goto end;
  11182. }
  11183. }
  11184. }// END FOR AC_QUANTITY
  11185. //The connectorId is 0
  11186. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11188. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11189. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11190. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11191. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11192. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11193. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11194. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11195. result = TRUE;
  11196. return result;
  11197. }
  11198. else
  11199. {
  11200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11201. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11202. }
  11203. if(strcmp(comfirmstr,"Accepted") == 0)
  11204. {
  11205. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11206. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11207. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11208. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11209. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11210. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11211. result = TRUE;
  11212. return result;
  11213. }
  11214. end:
  11215. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11216. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11217. return result;
  11218. }
  11219. int handleResetRequest(char *uuid, char *payload)
  11220. {
  11221. mtrace();
  11222. int result = FAIL;
  11223. char sstr[10]={0},sstrtemp[30]={ 0 };
  11224. char typestr[10]={0};
  11225. char comfirmstr[20]={0};
  11226. int c = 0;
  11227. char *loc;
  11228. DEBUG_INFO("handleResetRequest...\n");
  11229. strcpy(sstrtemp, stringtrimspace(payload));
  11230. loc = strstr(sstrtemp, "type");
  11231. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11232. c = 0;
  11233. while (loc[3+strlen("type")+c] != '\"')
  11234. {
  11235. sstr[c] = loc[3+strlen("type")+c];
  11236. c++;
  11237. }
  11238. sstr[c] = '\0';
  11239. strcpy(typestr,sstr);
  11240. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11241. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11242. {
  11243. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11244. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11245. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11246. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11247. }
  11248. else
  11249. {
  11250. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11251. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11252. result = PASS;
  11253. }
  11254. sendResetConfirmation(uuid, comfirmstr);
  11255. return result;
  11256. }
  11257. int handleSendLocalListRequest(char *uuid, char *payload)
  11258. {
  11259. mtrace();
  11260. int result = FAIL;
  11261. char comfirmstr[20];
  11262. int checkState_Faulted = FALSE;
  11263. json_object *SendLocalList;
  11264. DEBUG_INFO("handleSendLocalListRequest...\n");
  11265. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11266. {
  11267. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11268. goto end;
  11269. }
  11270. //check Charge Point state
  11271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11272. {
  11273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11274. {
  11275. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11276. }
  11277. }
  11278. for (int index = 0; index < CCS_QUANTITY; index++)
  11279. {
  11280. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11281. {
  11282. checkState_Faulted = TRUE; //OCPP Status
  11283. }
  11284. }
  11285. for (int index = 0; index < GB_QUANTITY; index++)
  11286. {
  11287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11288. {
  11289. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11290. }
  11291. }
  11292. //check Charge Point state
  11293. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11294. {
  11295. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11296. {
  11297. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11298. }
  11299. }
  11300. //check Charge Point state
  11301. for (int index = 0; index < AC_QUANTITY; index++)
  11302. {
  11303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11304. {
  11305. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11306. }
  11307. }
  11308. if(checkState_Faulted == TRUE)
  11309. {
  11310. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11311. goto end;
  11312. }
  11313. // Parsing payload
  11314. SendLocalList = json_tokener_parse(payload);
  11315. if(!is_error(SendLocalList))
  11316. {
  11317. // Required data
  11318. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11319. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11320. // Optional data
  11321. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11322. {
  11323. //Check UpdateType
  11324. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11325. {
  11326. //Local list full update
  11327. DEBUG_INFO("Local list full update.\n");
  11328. OCPP_getListVerion();
  11329. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11330. {
  11331. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11332. goto end;
  11333. }
  11334. OCPP_cleanLocalList();
  11335. }
  11336. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11337. {
  11338. //Local list different update
  11339. DEBUG_INFO("Local list different update.\n");
  11340. OCPP_getListVerion();
  11341. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11342. {
  11343. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11344. goto end;
  11345. }
  11346. }
  11347. else
  11348. {
  11349. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11350. goto end;
  11351. }
  11352. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11353. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11354. {
  11355. 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")));
  11356. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11357. {
  11358. 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")));
  11359. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11360. 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")));
  11361. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11362. 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")));
  11363. }
  11364. // Add to db
  11365. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11366. {
  11367. //Local list full update
  11368. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11369. idx,
  11370. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11371. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11372. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11373. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11374. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11375. // update list
  11376. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11377. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11378. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11379. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11380. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11381. }
  11382. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11383. {
  11384. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11385. idx,
  11386. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11387. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11388. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11389. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11390. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11391. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11392. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11393. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11394. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11395. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11396. }
  11397. }
  11398. }
  11399. else
  11400. {
  11401. //Check UpdateType
  11402. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11403. {
  11404. //Local list full update
  11405. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11406. OCPP_cleanLocalList();
  11407. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11408. goto end;
  11409. }
  11410. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11411. {
  11412. //Local list different update
  11413. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11414. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11415. goto end;
  11416. }
  11417. }
  11418. result = PASS;
  11419. }
  11420. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11421. end:
  11422. json_object_put(SendLocalList);
  11423. sendSendLocalListConfirmation(uuid, comfirmstr);
  11424. return result;
  11425. }
  11426. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11427. {
  11428. mtrace();
  11429. int result = FAIL;
  11430. struct StructSetChargingProfile SetProfileReq = {0};
  11431. int tempchargingProfileIdInt;
  11432. int chargingSchedulePeriodCount = 0;
  11433. char comfirmstr[20]={0};
  11434. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11435. char rmFileCmd[128]={0};
  11436. int profileQuantity = 0;
  11437. json_object *SetChargingProfile;
  11438. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11439. SetChargingProfile = json_tokener_parse(payload);
  11440. if(!is_error(SetChargingProfile))
  11441. {
  11442. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11443. {
  11444. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11445. }
  11446. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11447. {
  11448. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11449. {
  11450. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11451. }
  11452. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11453. {
  11454. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11455. }
  11456. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11457. {
  11458. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11459. }
  11460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11461. {
  11462. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11463. }
  11464. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11465. {
  11466. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11467. }
  11468. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11469. {
  11470. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11471. }
  11472. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11473. {
  11474. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11475. }
  11476. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11477. {
  11478. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11479. }
  11480. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11481. {
  11482. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11483. {
  11484. 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")));
  11485. }
  11486. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11487. {
  11488. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11489. }
  11490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11491. {
  11492. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11493. }
  11494. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11495. {
  11496. 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")));
  11497. }
  11498. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11499. {
  11500. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11501. if(chargingSchedulePeriodCount <= 10)
  11502. {
  11503. 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++)
  11504. {
  11505. 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)
  11506. {
  11507. 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"));
  11508. }
  11509. 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)
  11510. {
  11511. 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"));
  11512. }
  11513. 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)
  11514. {
  11515. 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"));
  11516. }
  11517. }
  11518. }
  11519. }
  11520. }
  11521. }
  11522. }
  11523. // Profile periods quantity check
  11524. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11525. {
  11526. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11527. goto end;
  11528. }
  11529. // Check invalid limit
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11531. {
  11532. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11533. {
  11534. 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)))) ||
  11535. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11536. {
  11537. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11538. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11539. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11540. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11541. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11542. goto end;
  11543. }
  11544. }
  11545. }
  11546. else
  11547. {
  11548. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11549. {
  11550. 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))
  11551. {
  11552. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11553. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11554. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11555. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11556. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11557. goto end;
  11558. }
  11559. }
  11560. }
  11561. // Profile purpose info check
  11562. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11563. {
  11564. FILE *fp;
  11565. char dataLine[4096]={0};
  11566. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11567. if(SetProfileReq.ConnectorId != 0)
  11568. {
  11569. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11570. goto end;
  11571. }
  11572. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11573. if (!fp)
  11574. {
  11575. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11576. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11577. }
  11578. else
  11579. {
  11580. while(fscanf(fp, "%s", dataLine) != EOF)
  11581. {
  11582. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11583. {
  11584. profileQuantity += 1;
  11585. }
  11586. }
  11587. }
  11588. fclose(fp);
  11589. }
  11590. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11591. {
  11592. FILE *fp;
  11593. char dataLine[4096]={0};
  11594. char filename[128]={0};
  11595. int tmpProfileQuantity;
  11596. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11597. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11598. {
  11599. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11600. goto end;
  11601. }
  11602. if(SetProfileReq.ConnectorId == 0)
  11603. {
  11604. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11605. {
  11606. tmpProfileQuantity = 0;
  11607. memset(filename, 0, ARRAY_SIZE(filename));
  11608. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  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. while(fscanf(fp, "%s", dataLine) != EOF)
  11618. {
  11619. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11620. {
  11621. tmpProfileQuantity += 1;
  11622. }
  11623. }
  11624. }
  11625. fclose(fp);
  11626. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11627. }
  11628. }
  11629. else
  11630. {
  11631. memset(filename, 0, ARRAY_SIZE(filename));
  11632. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11633. fp = fopen(filename, "r");
  11634. if (!fp)
  11635. {
  11636. DEBUG_INFO("%s does not create.\n", filename);
  11637. fp = fopen(filename, "w+");
  11638. }
  11639. else
  11640. {
  11641. while(fscanf(fp, "%s", dataLine) != EOF)
  11642. {
  11643. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11644. {
  11645. profileQuantity += 1;
  11646. }
  11647. }
  11648. }
  11649. fclose(fp);
  11650. }
  11651. }
  11652. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11653. {
  11654. int isMatchTransactiodId= FALSE;
  11655. FILE *fp;
  11656. char dataLine[4096]={0};
  11657. char filename[128]={0};
  11658. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11659. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11660. if(SetProfileReq.ConnectorId == 0)
  11661. {
  11662. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11663. goto end;
  11664. }
  11665. int tempIndex = 0;
  11666. //check Transaction active
  11667. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11668. {
  11669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11670. {
  11671. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11672. }
  11673. else
  11674. {
  11675. tempIndex = SetProfileReq.ConnectorId -1;
  11676. }
  11677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11678. {
  11679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11680. {
  11681. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11682. {
  11683. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11684. {
  11685. isMatchTransactiodId = TRUE;
  11686. break;
  11687. }
  11688. }
  11689. }
  11690. }
  11691. }
  11692. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11693. {
  11694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11695. {
  11696. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11697. }
  11698. else
  11699. {
  11700. tempIndex = SetProfileReq.ConnectorId -1;
  11701. }
  11702. for (int index = 0; index < CCS_QUANTITY; index++)
  11703. {
  11704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11705. {
  11706. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11707. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11708. {
  11709. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11710. {
  11711. isMatchTransactiodId = TRUE;
  11712. break;
  11713. }
  11714. }
  11715. }
  11716. }
  11717. }
  11718. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11719. {
  11720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11721. {
  11722. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11723. }
  11724. else
  11725. {
  11726. tempIndex = SetProfileReq.ConnectorId -1;
  11727. }
  11728. for (int index = 0; index < GB_QUANTITY; index++)
  11729. {
  11730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11731. {
  11732. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11733. {
  11734. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11735. {
  11736. isMatchTransactiodId = TRUE;
  11737. break;
  11738. }
  11739. }
  11740. }
  11741. }
  11742. }
  11743. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11744. {
  11745. tempIndex = SetProfileReq.ConnectorId -1;
  11746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11747. {
  11748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11749. {
  11750. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11751. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11752. {
  11753. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11754. {
  11755. isMatchTransactiodId = TRUE;
  11756. break;
  11757. }
  11758. }
  11759. }
  11760. }
  11761. }
  11762. else
  11763. {
  11764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11765. {
  11766. tempIndex = 2;
  11767. }
  11768. else
  11769. {
  11770. tempIndex = (SetProfileReq.ConnectorId -1);
  11771. }
  11772. for (int index = 0; index < AC_QUANTITY; index++)
  11773. {
  11774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11775. {
  11776. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11777. {
  11778. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11779. {
  11780. isMatchTransactiodId = TRUE;
  11781. break;
  11782. }
  11783. }
  11784. }
  11785. }
  11786. }
  11787. //check Transaction active
  11788. if(isMatchTransactiodId == FALSE)
  11789. {
  11790. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11791. goto end;
  11792. }
  11793. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11794. {
  11795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11796. goto end;
  11797. }
  11798. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11799. fp = fopen(filename, "r");
  11800. if (!fp)
  11801. {
  11802. DEBUG_INFO("%s does not create.\n", filename);
  11803. fp = fopen(filename, "w+");
  11804. }
  11805. else
  11806. {
  11807. //Check Charging Profile Count
  11808. while(fscanf(fp, "%s", dataLine) != EOF)
  11809. {
  11810. //DEBUG_INFO("word=%s\n",word);
  11811. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11812. {
  11813. profileQuantity += 1;
  11814. }
  11815. }
  11816. }
  11817. fclose(fp);
  11818. }
  11819. // Check ChargeProfileMaxStackLevel
  11820. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11821. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11822. {
  11823. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11824. goto end;
  11825. }
  11826. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11827. {
  11828. FILE *fp;
  11829. char dataLine[4096]={0};
  11830. char fnametemp[128]={0};
  11831. int tmpProfileQuantity;
  11832. //Check ChargePointMaxProfile.json exit
  11833. profileQuantity = 0;
  11834. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11835. {
  11836. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11837. //Check Charging Profile Count
  11838. tmpProfileQuantity = 0;
  11839. while(fscanf(fp, "%s", dataLine) != EOF)
  11840. {
  11841. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11842. {
  11843. profileQuantity += 1;
  11844. tmpProfileQuantity += 1;
  11845. }
  11846. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11847. }
  11848. fclose(fp);
  11849. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11850. }
  11851. //Check TxDefaultProfile_%d.json
  11852. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11853. {
  11854. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11855. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11856. if((access(fnametemp,F_OK))!=-1)
  11857. {
  11858. fp = fopen(fnametemp, "r");
  11859. //Check Charging Profile Count
  11860. tmpProfileQuantity = 0;
  11861. while(fscanf(fp, "%s", dataLine) != EOF)
  11862. {
  11863. //DEBUG_INFO("word=%s\n",word);
  11864. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11865. {
  11866. profileQuantity += 1;
  11867. tmpProfileQuantity += 1;
  11868. }
  11869. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11870. }
  11871. fclose(fp);
  11872. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11873. }
  11874. }
  11875. //Check TxProfile_%d.json
  11876. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11877. {
  11878. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11879. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11880. if((access(fnametemp,F_OK))!=-1)
  11881. {
  11882. fp = fopen(fnametemp, "r");
  11883. //Check Charging Profile Count
  11884. tmpProfileQuantity = 0;
  11885. while(fscanf(fp, "%s", dataLine) != EOF)
  11886. {
  11887. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11888. {
  11889. profileQuantity += 1;
  11890. tmpProfileQuantity += 1;
  11891. }
  11892. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11893. }
  11894. fclose(fp);
  11895. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11896. }
  11897. }
  11898. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11899. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11900. {
  11901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11902. goto end;
  11903. }
  11904. }
  11905. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11906. //**********************************Write to File********************************************************/
  11907. {
  11908. FILE *infile;
  11909. FILE *outfile;
  11910. char dataLine[4096]={0};
  11911. char filename[128]={0};
  11912. int chkChar=0;
  11913. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11914. {
  11915. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11916. {
  11917. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11918. }
  11919. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11920. {
  11921. if(SetProfileReq.ConnectorId==0)
  11922. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11923. else
  11924. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11925. }
  11926. else
  11927. {
  11928. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11929. }
  11930. infile = fopen (filename, "r");
  11931. outfile = fopen (tempfile, "w");
  11932. chkChar = fgetc(infile);
  11933. rewind(infile);
  11934. if(chkChar == EOF)
  11935. {
  11936. // Profile is empty
  11937. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11938. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11939. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11940. fclose(infile);
  11941. fclose(outfile);
  11942. sprintf(rmFileCmd,"rm -f %s",filename);
  11943. system(rmFileCmd);
  11944. rename(tempfile, filename);
  11945. }
  11946. else
  11947. {
  11948. // Profile is not empty
  11949. int ChargingProfileAdded = FALSE;
  11950. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11951. {
  11952. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11953. json_object *tmpChargingProfile;
  11954. tmpChargingProfile = json_tokener_parse(dataLine);
  11955. if(!is_error(SetChargingProfile))
  11956. {
  11957. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11958. {
  11959. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11960. {
  11961. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11962. }
  11963. }
  11964. }
  11965. json_object_put(tmpChargingProfile);
  11966. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11967. {
  11968. if(ChargingProfileAdded == FALSE)
  11969. {
  11970. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11971. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11972. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11973. ChargingProfileAdded = TRUE;
  11974. }
  11975. }
  11976. else
  11977. {
  11978. fprintf(outfile,"%s\n",dataLine);
  11979. if(ChargingProfileAdded == FALSE)
  11980. {
  11981. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11982. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11983. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11984. ChargingProfileAdded = TRUE;
  11985. }
  11986. }
  11987. } // end of while loop
  11988. fclose(infile);
  11989. fclose(outfile);
  11990. sprintf(rmFileCmd,"rm -f %s",filename);
  11991. system(rmFileCmd);
  11992. rename(tempfile, filename);
  11993. }
  11994. }
  11995. sleep(1);
  11996. result = TRUE;
  11997. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11998. }
  11999. end:
  12000. json_object_put(SetChargingProfile);
  12001. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12002. {
  12003. if(SetProfileReq.ConnectorId == 0)
  12004. {
  12005. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12006. {
  12007. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12008. }
  12009. }
  12010. else
  12011. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12012. }
  12013. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12014. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12015. return result;
  12016. }
  12017. int handleTriggerMessageRequest(char *uuid, char *payload)
  12018. {
  12019. mtrace();
  12020. int result = FAIL;
  12021. int connectorIdIsNULL = FALSE;
  12022. int connectorIdInt =0;
  12023. char sstr[40]={0},sstrtemp[100]={ 0 };
  12024. char requestedMessagestr[40]={0};
  12025. char comfirmstr[20]={0};
  12026. int c = 0;
  12027. char *loc;
  12028. DEBUG_INFO("handleTriggerMessageRequest\n");
  12029. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12030. strcpy(sstrtemp, stringtrimspace(payload));
  12031. c = 0;
  12032. loc = strstr(sstrtemp, "requestedMessage");
  12033. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12034. {
  12035. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12036. c++;
  12037. }
  12038. sstr[c] = '\0';
  12039. strcpy(requestedMessagestr, sstr);
  12040. c = 0;
  12041. loc = strstr(sstrtemp, "connectorId");
  12042. if(loc == NULL)
  12043. {
  12044. connectorIdIsNULL = TRUE;
  12045. }
  12046. else
  12047. {
  12048. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12049. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12050. {
  12051. sstr[c] = loc[strlen("connectorId")+2+c];
  12052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12053. c++;
  12054. }
  12055. sstr[c] = '\0';
  12056. connectorIdInt = atoi(sstr);
  12057. }
  12058. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12059. {
  12060. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12061. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12062. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12063. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12064. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12065. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12066. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12067. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12068. {
  12069. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12070. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12071. return TRUE;
  12072. }
  12073. else
  12074. {
  12075. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12076. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12077. }
  12078. }
  12079. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12080. {
  12081. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12082. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12083. return TRUE;
  12084. }
  12085. //==========================
  12086. // Trigger message
  12087. //==========================
  12088. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12089. {
  12090. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12091. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12092. {
  12093. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12094. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12095. }
  12096. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12097. }
  12098. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12099. {
  12100. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12101. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12102. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12103. }
  12104. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12105. {
  12106. //sendBootNotificationRequest();
  12107. server_sign = FALSE;
  12108. }
  12109. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12110. {
  12111. refreshStartTimer(&clientTime.Heartbeat);
  12112. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12113. }
  12114. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12115. {
  12116. if(connectorIdIsNULL == FALSE)
  12117. {
  12118. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12119. {
  12120. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12121. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12122. }
  12123. }
  12124. else
  12125. {
  12126. for(int idx=0;idx< gunTotalNumber;idx++)
  12127. {
  12128. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12129. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12130. }
  12131. }
  12132. }
  12133. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12134. {
  12135. if(connectorIdIsNULL == FALSE)
  12136. {
  12137. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12138. {
  12139. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12140. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12141. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12142. }
  12143. }
  12144. else
  12145. {
  12146. for(int idx=0;idx< gunTotalNumber;idx++)
  12147. {
  12148. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12149. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12150. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12151. }
  12152. }
  12153. }
  12154. return result;
  12155. }
  12156. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12157. {
  12158. mtrace();
  12159. int result = FAIL;
  12160. int connectorIdInt =0;
  12161. char comfirmstr[20]={0};
  12162. int tempIndex = 0;
  12163. json_object *UnlockConnector;
  12164. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12165. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12166. UnlockConnector = json_tokener_parse(payload);
  12167. if(!is_error(UnlockConnector))
  12168. {
  12169. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12170. {
  12171. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12172. }
  12173. }
  12174. json_object_put(UnlockConnector);
  12175. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12176. if(gunTotalNumber == 0)
  12177. {
  12178. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12179. goto end;
  12180. }
  12181. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12182. {
  12183. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12184. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12185. goto end;
  12186. }
  12187. else
  12188. {
  12189. //check Transaction active
  12190. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12193. {
  12194. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12195. }
  12196. else
  12197. {
  12198. tempIndex = connectorIdInt -1;
  12199. }
  12200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12201. {
  12202. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12203. {
  12204. //stop Transaction
  12205. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12206. }
  12207. }
  12208. }
  12209. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12210. {
  12211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12212. {
  12213. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12214. }
  12215. else
  12216. {
  12217. tempIndex = connectorIdInt -1;
  12218. }
  12219. for (int index = 0; index < CCS_QUANTITY; index++)
  12220. {
  12221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12222. {
  12223. //stop Transaction
  12224. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12225. }
  12226. }
  12227. }
  12228. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12229. {
  12230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12231. {
  12232. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12233. }
  12234. else
  12235. {
  12236. tempIndex = connectorIdInt -1;
  12237. }
  12238. for (int index = 0; index < GB_QUANTITY; index++)
  12239. {
  12240. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12241. {
  12242. //stop Transaction
  12243. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12244. }
  12245. }
  12246. }
  12247. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12248. {
  12249. tempIndex = connectorIdInt -1;
  12250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12251. {
  12252. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12253. {
  12254. //stop Transaction
  12255. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12256. }
  12257. }
  12258. }
  12259. else
  12260. {
  12261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12262. {
  12263. tempIndex = 2;
  12264. }
  12265. else
  12266. {
  12267. tempIndex = connectorIdInt-1;
  12268. }
  12269. for (int index = 0; index < AC_QUANTITY; index++)
  12270. {
  12271. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12272. {
  12273. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12274. }
  12275. }
  12276. }
  12277. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12278. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12279. result = TRUE;
  12280. return result;
  12281. }
  12282. end:
  12283. //json_object_put(obj); --- remove temporally
  12284. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12285. return result;
  12286. }
  12287. static char UpdateFirmwarepayloadData[300]={0};
  12288. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12289. {
  12290. mtrace();
  12291. int result = FAIL;
  12292. pthread_t t;
  12293. sendUpdateFirmwareConfirmation(uuid);
  12294. memset(UpdateFirmwarepayloadData, 0, 300);
  12295. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12296. if(!interLock.isUpdateFirmwareGoing)
  12297. {
  12298. interLock.isUpdateFirmwareGoing = 1;
  12299. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12300. sleep(1);
  12301. }
  12302. else
  12303. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12304. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12305. return result;
  12306. }
  12307. void *UpdateFirmwareProcess(void *data)
  12308. {
  12309. pthread_detach(pthread_self());
  12310. mtrace();
  12311. int retriesInt =0, retryIntervalInt=0;
  12312. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12313. int port=0;
  12314. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12315. int isSuccess = 0;
  12316. char ftpbuf[512];
  12317. char temp[100];
  12318. char * pch;
  12319. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12320. json_object *UpdateFirmware;
  12321. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12322. if(!is_error(UpdateFirmware))
  12323. {
  12324. // Required data
  12325. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12326. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12327. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12328. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12329. // Optional data
  12330. if(json_object_object_get(UpdateFirmware, "retries"))
  12331. {
  12332. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12333. }
  12334. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12335. {
  12336. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12337. }
  12338. }
  12339. json_object_put(UpdateFirmware);
  12340. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12341. memset(path, 0, ARRAY_SIZE(path));
  12342. // Wait retrieveData
  12343. if(strlen(retrieveDatestr) > 10)
  12344. {
  12345. do
  12346. {
  12347. sleep(1);
  12348. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12349. }
  12350. // Ready to download
  12351. system("rm -f /mnt/*");
  12352. if(strncmp(locationstr,"http", 4) == 0)
  12353. {
  12354. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12355. sprintf(ftppath,"/%s", path);
  12356. DEBUG_INFO("locationstr: %s\n", locationstr);
  12357. DEBUG_INFO("protocol: %s\n",protocol);
  12358. DEBUG_INFO("host: %s\n",host);
  12359. DEBUG_INFO("path: %s\n",path);
  12360. DEBUG_INFO("ftppath: %s\n",ftppath);
  12361. int ftppathlen=strlen(ftppath);
  12362. int i=1;
  12363. char filenametemp[50];
  12364. while(i < ftppathlen)
  12365. {
  12366. int len=ftppathlen-i;
  12367. if(ftppath[len]== 47) // '/' ascll code: 47
  12368. {
  12369. DEBUG_INFO("compare '/' all right\n");
  12370. break;
  12371. }
  12372. i=i+1;
  12373. }
  12374. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12375. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12376. filenametemp[i+1] = 0;
  12377. do
  12378. {
  12379. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12380. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12381. sleep(1);
  12382. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12383. if(!isSuccess)
  12384. {
  12385. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12386. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12387. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12388. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12389. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12390. }
  12391. else
  12392. {
  12393. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12394. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12395. }
  12396. retriesInt--;
  12397. }while((isSuccess == 0)&&(retriesInt >= 0));
  12398. }
  12399. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12400. {
  12401. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12402. memset(temp, 0, ARRAY_SIZE(temp));
  12403. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12404. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12405. int ftppathlen=strlen(ftpbuf);
  12406. int i=1;
  12407. char filenametemp[50];
  12408. while(i < ftppathlen)
  12409. {
  12410. int len=ftppathlen-i;
  12411. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12412. {
  12413. DEBUG_INFO(" compare '/' all right\n");
  12414. break;
  12415. }
  12416. i=i+1;
  12417. }
  12418. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12419. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12420. filenametemp[i+1] = 0;
  12421. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12422. pch=strchr(temp,'@');
  12423. if(pch==NULL)
  12424. {
  12425. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12426. protocol, host, &port, path);
  12427. strcpy(user,"anonymous");
  12428. strcpy(password,"");
  12429. }
  12430. else
  12431. {
  12432. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12433. protocol, user, password, host, &port, path);
  12434. }
  12435. sscanf(host,"%[^/]%s",host1, path1);
  12436. sprintf(ftppath,"%s", path1);
  12437. //DEBUG_INFO("protocol =%s\n",protocol);
  12438. //DEBUG_INFO("user =%s\n",user);
  12439. //DEBUG_INFO("password =%s\n",password);
  12440. //DEBUG_INFO("host1 =%s\n",host1);
  12441. //DEBUG_INFO("port =%d\n",port);
  12442. //DEBUG_INFO("path1 =%s\n",path1);
  12443. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12444. //ftpFile(host, user, password, port, ftppath, fname);
  12445. //download firmware pthred
  12446. if(port == 0)
  12447. {
  12448. port = 21;
  12449. }
  12450. do
  12451. {
  12452. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12453. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12454. sleep(1);
  12455. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12456. if(!isSuccess)
  12457. {
  12458. //BulldogUtil.sleepMs(interval*1000);
  12459. DEBUG_INFO("Update firmware request and download file fail.\n");
  12460. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12461. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12462. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12463. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12464. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12465. }
  12466. else
  12467. {
  12468. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12469. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12470. }
  12471. retriesInt--;
  12472. }while((!isSuccess)&&(retriesInt >= 0));
  12473. }
  12474. else
  12475. {
  12476. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12477. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12478. sleep(1);
  12479. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12480. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12481. }
  12482. // OCPPPH only, must announce CSU upgrade firmware
  12483. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12484. interLock.isUpdateFirmwareGoing = 0;
  12485. pthread_exit(NULL);
  12486. }
  12487. int handleCertificateSignedRequest(char *uuid, char *payload)
  12488. {
  12489. mtrace();
  12490. int result = PASS;
  12491. json_object *CertificateSigned;
  12492. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12493. CertificateSigned = json_tokener_parse(payload);
  12494. if(!is_error(CertificateSigned))
  12495. {
  12496. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12497. }
  12498. json_object_put(CertificateSigned);
  12499. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12500. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12501. fclose(fp);
  12502. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12503. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12504. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12505. sendCertificateSignedConfirmation(uuid);
  12506. return result;
  12507. }
  12508. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12509. {
  12510. mtrace();
  12511. int result = PASS;
  12512. json_object *DeleteCertificate;
  12513. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12514. DeleteCertificate = json_tokener_parse(payload);
  12515. if(!is_error(DeleteCertificate))
  12516. {
  12517. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12518. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12519. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12520. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12521. }
  12522. json_object_put(DeleteCertificate);
  12523. /*
  12524. * TODO: Delete certificateSigned process
  12525. */
  12526. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12527. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12528. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12529. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12530. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12531. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12532. sendDeleteCertificateConfirmation(uuid);
  12533. return result;
  12534. }
  12535. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12536. {
  12537. mtrace();
  12538. int result = PASS;
  12539. json_object *ExtendedTriggerMessage;
  12540. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12541. ExtendedTriggerMessage = json_tokener_parse(payload);
  12542. if(!is_error(ExtendedTriggerMessage))
  12543. {
  12544. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12545. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12546. {
  12547. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12548. }
  12549. else
  12550. {
  12551. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12552. }
  12553. }
  12554. json_object_put(ExtendedTriggerMessage);
  12555. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12556. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12557. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12558. {
  12559. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12560. }
  12561. else
  12562. {
  12563. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12564. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12565. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12566. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12567. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12568. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12569. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12570. {
  12571. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12572. }
  12573. else
  12574. {
  12575. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12576. }
  12577. }
  12578. sendExtendedTriggerMessageConfirmation(uuid);
  12579. //==========================
  12580. // Trigger message
  12581. //==========================
  12582. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12583. {
  12584. //sendBootNotificationRequest();
  12585. server_sign = FALSE;
  12586. }
  12587. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12588. {
  12589. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12590. }
  12591. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12592. {
  12593. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12594. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12595. {
  12596. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12597. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12598. }
  12599. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12600. }
  12601. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12602. {
  12603. refreshStartTimer(&clientTime.Heartbeat);
  12604. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12605. }
  12606. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12607. {
  12608. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12609. {
  12610. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12611. }
  12612. else
  12613. {
  12614. for(int idx=0;idx< gunTotalNumber;idx++)
  12615. {
  12616. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12617. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12618. }
  12619. }
  12620. }
  12621. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12622. {
  12623. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12624. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12625. {
  12626. 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\" &");
  12627. }
  12628. }
  12629. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12630. {
  12631. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12632. {
  12633. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12634. }
  12635. else
  12636. {
  12637. for(int idx=0;idx< gunTotalNumber;idx++)
  12638. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12639. }
  12640. }
  12641. return result;
  12642. }
  12643. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12644. {
  12645. mtrace();
  12646. int result = PASS;
  12647. json_object *GetInstalledCertificateIds;
  12648. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12649. GetInstalledCertificateIds = json_tokener_parse(payload);
  12650. if(!is_error(GetInstalledCertificateIds))
  12651. {
  12652. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12653. }
  12654. json_object_put(GetInstalledCertificateIds);
  12655. /*
  12656. * TODO: Return installed certificate process
  12657. */
  12658. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12659. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12660. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12661. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12662. sendGetInstalledCertificateIdsConfirmation(uuid);
  12663. return result;
  12664. }
  12665. int handleGetLogRequest(char *uuid, char *payload)
  12666. {
  12667. mtrace();
  12668. int result = PASS;
  12669. json_object *GetLog;
  12670. DEBUG_INFO("handleGetLogRequest...\n");
  12671. GetLog = json_tokener_parse(payload);
  12672. if(!is_error(GetLog))
  12673. {
  12674. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12675. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12676. if(json_object_object_get(GetLog, "retries") != NULL)
  12677. {
  12678. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12679. }
  12680. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12681. {
  12682. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12683. }
  12684. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12685. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12686. {
  12687. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12688. }
  12689. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12690. {
  12691. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12692. }
  12693. }
  12694. json_object_put(GetLog);
  12695. /*
  12696. * TODO: Upload log process
  12697. */
  12698. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12699. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12700. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12701. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12702. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12703. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12704. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12705. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12706. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12707. sendGetLogConfirmation(uuid);
  12708. return result;
  12709. }
  12710. int handleInstallCertificateRequest(char *uuid, char *payload)
  12711. {
  12712. mtrace();
  12713. int result = PASS;
  12714. json_object *InstallCertificate;
  12715. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12716. InstallCertificate = json_tokener_parse(payload);
  12717. if(!is_error(InstallCertificate))
  12718. {
  12719. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12720. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12721. /*
  12722. * TODO: Install certificate process
  12723. */
  12724. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12725. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12726. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12727. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12728. sendInstallCertificateConfirmation(uuid);
  12729. }
  12730. json_object_put(InstallCertificate);
  12731. return result;
  12732. }
  12733. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12734. {
  12735. mtrace();
  12736. int result = PASS;
  12737. json_object *SignedUpdateFirmware;
  12738. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12739. SignedUpdateFirmware = json_tokener_parse(payload);
  12740. if(!is_error(SignedUpdateFirmware))
  12741. {
  12742. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12743. {
  12744. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12745. }
  12746. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12747. {
  12748. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12749. }
  12750. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12751. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12752. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12753. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12754. {
  12755. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12756. }
  12757. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12758. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12759. }
  12760. json_object_put(SignedUpdateFirmware);
  12761. /*
  12762. * TODO: Upgrade firmware process
  12763. */
  12764. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12765. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12766. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12767. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12768. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12769. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12770. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12771. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12772. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12773. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12774. sendInstallCertificateConfirmation(uuid);
  12775. return result;
  12776. }
  12777. int handleUnknownRequest(char *uuid, char *payload)
  12778. {
  12779. mtrace();
  12780. int result = PASS;
  12781. DEBUG_INFO("handleUnknownRequest...\n");
  12782. sendUnknownConfirmation(uuid);
  12783. result = PASS;
  12784. return result;
  12785. }
  12786. //==========================================
  12787. // Handle server response routine
  12788. //==========================================
  12789. void handleAuthorizeResponse(char *payload, int gun_index)
  12790. {
  12791. mtrace();
  12792. char expiryDatestr[30]={0};
  12793. char parentIdTagstr[20]={0};
  12794. char statusstr[20]={0};
  12795. int expiryDateISNULL=FALSE;
  12796. int parentIdTagISNULL=FALSE;
  12797. DEBUG_INFO("handleAuthorizeResponse...\n");
  12798. json_object *Authorize;
  12799. Authorize = json_tokener_parse(payload);
  12800. if(!is_error(Authorize))
  12801. {
  12802. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12803. {
  12804. // Required data
  12805. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12806. // Optional data
  12807. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12808. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12809. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12810. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12811. }
  12812. }
  12813. json_object_put(Authorize);
  12814. if(expiryDateISNULL == FALSE)
  12815. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12816. if(parentIdTagISNULL == FALSE)
  12817. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12818. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12819. //Update idTag information to authorization cache if supproted
  12820. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12821. {
  12822. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12823. }
  12824. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12825. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12826. authorizeRetryTimes = 0;
  12827. }
  12828. void handleBootNotificationResponse(char *payload, int gun_index)
  12829. {
  12830. mtrace();
  12831. char statusStr[12]={0};
  12832. char currentTimeStr[30]={0};
  12833. int intervalInt = 0;
  12834. DEBUG_INFO("handleBootNotificationResponse...\n");
  12835. json_object *BootNotification;
  12836. BootNotification = json_tokener_parse(payload);
  12837. if(!is_error(BootNotification))
  12838. {
  12839. // Required data
  12840. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12841. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12842. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12843. }
  12844. json_object_put(BootNotification);
  12845. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12846. BootNotificationInterval = intervalInt;
  12847. HeartBeatWaitTime = intervalInt;
  12848. //write back to ShmOCPP16DataPH->BootNotification
  12849. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12850. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12851. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12852. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12853. {
  12854. if((intervalInt == 0) || (intervalInt >= 10))
  12855. {
  12856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12857. HeartBeatWaitTime = intervalInt;
  12858. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12859. }
  12860. server_sign = TRUE;
  12861. server_pending =FALSE;
  12862. }
  12863. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12864. {
  12865. server_pending = TRUE;
  12866. }
  12867. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12868. srand(time(NULL));
  12869. refreshStartTimer(&clientTime.Heartbeat);
  12870. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12871. SetOcppConnStatus(TRUE);
  12872. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12873. }
  12874. void handleDataTransferResponse(char *payload, int gun_index)
  12875. {
  12876. json_object *DataTransfer = json_tokener_parse(payload);
  12877. if(!is_error(DataTransfer))
  12878. {
  12879. // Required data
  12880. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12881. // Optional data
  12882. if(json_object_object_get(DataTransfer, "data") != NULL)
  12883. {
  12884. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12885. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12886. if(!is_error(Data))
  12887. {
  12888. if(json_object_object_get(Data, "msgId") != NULL)
  12889. {
  12890. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12891. {
  12892. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  12893. }
  12894. }
  12895. }
  12896. json_object_put(Data);
  12897. }
  12898. }
  12899. json_object_put(DataTransfer);
  12900. }
  12901. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12902. {
  12903. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12904. //struct json_object *obj;
  12905. // obj = json_tokener_parse(payload);
  12906. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12907. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12908. //No fields are defined.
  12909. }
  12910. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12911. {
  12912. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12913. //struct json_object *obj;
  12914. // obj = json_tokener_parse(payload);
  12915. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12916. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12917. //No fields are defined.
  12918. }
  12919. void handleHeartbeatResponse(char *payload, int gun_index)
  12920. {
  12921. mtrace();
  12922. DEBUG_INFO("handleHeartbeatResponse...\n");
  12923. json_object *Heartbeat;
  12924. Heartbeat = json_tokener_parse(payload);
  12925. if(!is_error(Heartbeat))
  12926. {
  12927. // Required data
  12928. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12929. }
  12930. json_object_put(Heartbeat);
  12931. if(FirstHeartBeat == 0)
  12932. {
  12933. FirstHeartBeat = 1;
  12934. DEBUG_INFO("FirstHeartBeat \n");
  12935. }
  12936. HeartBeatWithNOResponse = 0;
  12937. refreshStartTimer(&clientTime.Heartbeat);
  12938. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12939. }
  12940. void handleMeterValuesResponse(char *payload, int gun_index)
  12941. {
  12942. mtrace();
  12943. DEBUG_INFO("handleMeterValuesResponse...\n");
  12944. isQueueSendable = 1;
  12945. }
  12946. void handleStartTransactionResponse(char *payload, int gun_index)
  12947. {
  12948. mtrace();
  12949. //int transactionIdInt = 0;
  12950. FILE *outfile;
  12951. char data[100]={0};
  12952. DEBUG_INFO("handleStartTransactionResponse...\n");
  12953. json_object *StartTransaction;
  12954. StartTransaction = json_tokener_parse(payload);
  12955. if(!is_error(StartTransaction))
  12956. {
  12957. // Required data
  12958. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12959. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12960. // Optional data
  12961. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12962. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12963. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12964. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12965. }
  12966. json_object_put(StartTransaction);
  12967. isQueueSendable = 1;
  12968. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12969. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12970. //-----------Start : write to the Queue TransactionId file -----------------//
  12971. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12972. {}
  12973. else
  12974. {
  12975. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12976. if(log == NULL)
  12977. {
  12978. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12979. return ;
  12980. }
  12981. else
  12982. {
  12983. fclose(log);
  12984. }
  12985. }
  12986. // open file for writing
  12987. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12988. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12989. {
  12990. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12991. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12992. fputs(data, outfile);
  12993. fclose (outfile);
  12994. }
  12995. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12996. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12997. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12998. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12999. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13000. }
  13001. void handleStatusNotificationResponse(char *payload, int gun_index)
  13002. {
  13003. mtrace();
  13004. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13005. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13006. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13007. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13008. }
  13009. void handleStopTransactionnResponse(char *payload, int gun_index)
  13010. {
  13011. mtrace();
  13012. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13013. json_object *StopTransaction;
  13014. StopTransaction = json_tokener_parse(payload);
  13015. if(!is_error(StopTransaction))
  13016. {
  13017. // Optional data
  13018. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13019. {
  13020. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13021. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13023. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13024. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13025. }
  13026. }
  13027. json_object_put(StopTransaction);
  13028. isQueueSendable = 1;
  13029. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13030. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13031. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13032. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13033. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13034. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13035. }
  13036. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13037. {
  13038. mtrace();
  13039. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13040. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13041. }
  13042. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13043. {
  13044. mtrace();
  13045. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13046. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13047. }
  13048. void handleSignCertificateResponse(char *payload, int gun_index)
  13049. {
  13050. mtrace();
  13051. DEBUG_INFO("handleSignCertificateResponse...\n");
  13052. json_object *SignCertificate;
  13053. SignCertificate = json_tokener_parse(payload);
  13054. if(!is_error(SignCertificate))
  13055. {
  13056. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13057. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13058. }
  13059. json_object_put(SignCertificate);
  13060. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13061. }
  13062. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13063. {
  13064. mtrace();
  13065. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13066. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13067. }
  13068. //==========================================
  13069. // Handle Error routine
  13070. //==========================================
  13071. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13072. {
  13073. mtrace();
  13074. #ifdef SystemLogMessage
  13075. DEBUG_INFO("errorCode: %s\n", errorCode);
  13076. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13077. DEBUG_INFO("errorDetails: %s\n", payload);
  13078. #endif
  13079. }
  13080. //===============================================
  13081. // Common routine
  13082. //===============================================
  13083. int initialConfigurationTable(void)
  13084. {
  13085. //clock_t start_t, end_t, total_t;
  13086. FILE *fp;
  13087. FILE *outfile;
  13088. char str[512]={0};
  13089. char sstr[256]={0};
  13090. int c = 0;
  13091. char *loc;
  13092. int confVersion = 12;
  13093. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13094. //start_t = clock();
  13095. //printf("Starting of the program, start_t = %ld\n", start_t);
  13096. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13097. // Check configuration file size is correct
  13098. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13099. {
  13100. struct stat st;
  13101. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13102. if(st.st_size < 3100)
  13103. {
  13104. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13105. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13106. }
  13107. }
  13108. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13109. {
  13110. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13111. if(outfile == NULL)
  13112. {
  13113. DEBUG_INFO("Error opening file\n");
  13114. return FALSE;
  13115. }
  13116. /*Core Profile*/
  13117. //AllowOfflineTxForUnknownId
  13118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13122. //AuthorizationCacheEnabled
  13123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13127. //AuthorizeRemoteTxRequests
  13128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13132. //BlinkRepeat
  13133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13137. //ClockAlignedDataInterval
  13138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13142. //ConnectionTimeOut
  13143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13147. //GetConfigurationMaxKeys
  13148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13152. // HeartbeatInterval
  13153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13157. // LightIntensity
  13158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13162. // LocalAuthorizeOffline
  13163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13167. // LocalPreAuthorize
  13168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13172. // MaxEnergyOnInvalidId
  13173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13177. // MeterValuesAlignedData
  13178. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13181. 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" );
  13182. else
  13183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13185. // MeterValuesAlignedDataMaxLength
  13186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13190. else
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13193. // MeterValuesSampledData
  13194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13197. 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" );
  13198. else
  13199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13201. // MeterValuesSampledDataMaxLength
  13202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13206. else
  13207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13209. // MeterValueSampleInterval
  13210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13214. // MinimumStatusDuration
  13215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13218. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13220. // NumberOfConnectors
  13221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13224. {
  13225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13226. }
  13227. else
  13228. {
  13229. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13230. }
  13231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13232. // ResetRetries
  13233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13237. // ConnectorPhaseRotation
  13238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13242. // ConnectorPhaseRotationMaxLength
  13243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13247. // StopTransactionOnEVSideDisconnect
  13248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13252. // StopTransactionOnInvalidId
  13253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13257. // StopTxnAlignedData
  13258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13262. // StopTxnAlignedDataMaxLength
  13263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13267. // StopTxnSampledData
  13268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13272. else
  13273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13275. // StopTxnSampledDataMaxLength
  13276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13279. {
  13280. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13281. }
  13282. else
  13283. {
  13284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13285. }
  13286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13287. // SupportedFeatureProfiles
  13288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13292. // SupportedFeatureProfilesMaxLength
  13293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13297. // TransactionMessageAttempts
  13298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13301. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13303. // TransactionMessageRetryInterval
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13307. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13309. // UnlockConnectorOnEVSideDisconnect
  13310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13314. // WebSocketPingInterval
  13315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13319. // QueueOffLineMeterValues
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13324. // AuthorizationKey
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13329. // SecurityProfile
  13330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13334. // DefaultPrice
  13335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13339. // CustomDisplayCostAndPrice
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13344. // CustomIdleFeeAfterStop
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13349. // SystemUptimeSec
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13354. // FreeVend
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13359. // OcppServer
  13360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13362. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13364. // MaintainServer
  13365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13367. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13369. // StatusNotificationPeriodically
  13370. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13374. // StatusNotificationInterval
  13375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13379. // Configuration Version
  13380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13384. //* Local Auth List Management Profile*/
  13385. #if 0
  13386. //For OCTT Test Case
  13387. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13390. #endif
  13391. #if 1
  13392. //LocalAuthListEnabled
  13393. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13397. #endif
  13398. //LocalAuthListMaxLength
  13399. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13403. //SendLocalListMaxLength
  13404. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13408. //ReserveConnectorZeroSupported
  13409. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13413. //* Smart Charging Profile */
  13414. //ChargeProfileMaxStackLevel
  13415. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13419. // ChargingScheduleAllowedChargingRateUnit
  13420. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13424. // ChargingScheduleMaxPeriods
  13425. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13429. // ConnectorSwitch3to1PhaseSupported
  13430. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13434. // MaxChargingProfilesInstalled
  13435. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13439. fclose(outfile);
  13440. }
  13441. else
  13442. {
  13443. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13444. char keystr[60]={0};
  13445. char readonlystr[10]={0};
  13446. char valuestr[256]={0};
  13447. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13448. if(fp == NULL) {
  13449. DEBUG_INFO("Error opening file");
  13450. return FALSE;
  13451. }
  13452. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13453. {
  13454. //DEBUG_INFO("Get Configuration \n");
  13455. if(strlen(str) > 0)
  13456. {
  13457. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13458. //*************************key*********************************/
  13459. if(strstr(str, "key") != NULL)
  13460. {
  13461. loc = strstr(str, "key");
  13462. c = 0;
  13463. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13464. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13465. {
  13466. sstr[c] = loc[strlen("key")+3+c];
  13467. c++;
  13468. }
  13469. sstr[c] = '\0';
  13470. strcpy(keystr,sstr);
  13471. }
  13472. //*************************readonly*********************************/
  13473. if(strstr(str, "readonly") != NULL)
  13474. {
  13475. loc = strstr(str, "readonly");
  13476. c = 0;
  13477. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13478. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13479. {
  13480. sstr[c] = loc[strlen("readonly")+2+c];
  13481. c++;
  13482. }
  13483. sstr[c] = '\0';
  13484. strcpy(readonlystr,sstr);
  13485. }
  13486. //*************************value*********************************/
  13487. if(strstr(str, "value") != NULL)
  13488. {
  13489. loc = strstr(str, "value");
  13490. c = 0;
  13491. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13492. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13493. {
  13494. sstr[c] = loc[strlen("value")+3+c];
  13495. c++;
  13496. }
  13497. sstr[c] = '\0';
  13498. strcpy(valuestr,sstr);
  13499. }
  13500. // DEBUG_INFO("keystr=%s\n",keystr);
  13501. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13502. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13503. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13504. {
  13505. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13508. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13509. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13510. }
  13511. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13512. {
  13513. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13516. }
  13517. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13518. {
  13519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13521. }
  13522. if(strcmp(keystr, "BlinkRepeat") == 0)
  13523. {
  13524. //Charger.BlinkRepeat = Integer.parseInt(value);
  13525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13527. }
  13528. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13529. {
  13530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13532. }
  13533. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13534. {
  13535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13537. }
  13538. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13539. {
  13540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13542. }
  13543. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13544. {
  13545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13547. HeartBeatWaitTime = atoi(valuestr);
  13548. }
  13549. if(strcmp(keystr, "LightIntensity") == 0)
  13550. {
  13551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13553. }
  13554. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13555. {
  13556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13558. }
  13559. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13560. {
  13561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13563. }
  13564. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13565. {
  13566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13568. }
  13569. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13570. {
  13571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13573. }
  13574. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13575. {
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13578. }
  13579. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13580. {
  13581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13583. }
  13584. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13585. {
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13587. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13588. }
  13589. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13590. {
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13593. }
  13594. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13595. {
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13598. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13599. }
  13600. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13601. {
  13602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13604. }
  13605. if(strcmp(keystr, "ResetRetries") == 0)
  13606. {
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13609. }
  13610. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13611. {
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13613. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13614. }
  13615. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13616. {
  13617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13619. }
  13620. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13621. {
  13622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13624. }
  13625. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13626. {
  13627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13629. }
  13630. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13631. {
  13632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13633. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13634. }
  13635. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13636. {
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13639. }
  13640. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13641. {
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13644. }
  13645. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13646. {
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13649. }
  13650. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13651. {
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13654. }
  13655. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13656. {
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13659. }
  13660. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13661. {
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13664. TransactionMessageAttemptsValue = atoi(valuestr);
  13665. }
  13666. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13667. {
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13670. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13671. }
  13672. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13673. {
  13674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13676. }
  13677. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13678. {
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13681. }
  13682. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13683. {
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13686. }
  13687. if(strcmp(keystr, "AuthorizationKey") == 0)
  13688. {
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13690. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13692. }
  13693. if(strcmp(keystr, "SecurityProfile") == 0)
  13694. {
  13695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13696. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13698. }
  13699. if(strcmp(keystr, "DefaultPrice") == 0)
  13700. {
  13701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13703. }
  13704. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13705. {
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13708. }
  13709. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13710. {
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13713. }
  13714. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13715. {
  13716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13717. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13718. }
  13719. if(strcmp(keystr, "FreeVend") == 0)
  13720. {
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13723. }
  13724. if(strcmp(keystr, "OcppServer") == 0)
  13725. {
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13727. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13728. }
  13729. if(strcmp(keystr, "MaintainServer") == 0)
  13730. {
  13731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13732. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13733. }
  13734. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13735. {
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13738. }
  13739. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13740. {
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13743. }
  13744. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13745. {
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13748. }
  13749. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13750. {
  13751. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13753. }
  13754. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13755. {
  13756. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13758. }
  13759. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13760. {
  13761. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13763. }
  13764. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13765. {
  13766. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13768. }
  13769. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13770. {
  13771. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13772. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13773. }
  13774. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13775. {
  13776. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13778. }
  13779. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13780. {
  13781. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13783. }
  13784. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13785. {
  13786. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13788. }
  13789. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13790. {
  13791. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13793. }
  13794. }
  13795. }
  13796. fclose(fp);
  13797. }
  13798. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13799. {
  13800. return PASS;
  13801. }
  13802. else
  13803. {
  13804. return FAIL;
  13805. }
  13806. }
  13807. void StoreConfigurationTable(void)
  13808. {
  13809. FILE *outfile;
  13810. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13811. if(outfile == NULL)
  13812. {
  13813. DEBUG_INFO("Error opening file");
  13814. return ;
  13815. }
  13816. /*Core Profile*/
  13817. //AllowOfflineTxForUnknownId
  13818. /*
  13819. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13820. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13823. */
  13824. //DEBUG_INFO("data=%s\n",data);
  13825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13826. //AuthorizationCacheEnabled
  13827. /*
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13831. */
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13833. //AuthorizeRemoteTxRequests
  13834. /*
  13835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13838. */
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13840. //BlinkRepeat
  13841. /*
  13842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13845. */
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13847. //ClockAlignedDataInterval
  13848. /*
  13849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13852. */
  13853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13854. //ConnectionTimeOut
  13855. /*
  13856. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13859. */
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13861. //GetConfigurationMaxKeys
  13862. /*
  13863. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13866. */
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13868. // HeartbeatInterval
  13869. /*
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13873. */
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13875. // LightIntensity
  13876. /*
  13877. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13880. */
  13881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13882. // LocalAuthorizeOffline
  13883. /*
  13884. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13887. */
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13889. // LocalPreAuthorize
  13890. /*
  13891. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13894. */
  13895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13896. // MaxEnergyOnInvalidId
  13897. /*
  13898. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13901. */
  13902. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13904. // MeterValuesAlignedData
  13905. /*
  13906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13909. */
  13910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13911. // MeterValuesAlignedDataMaxLength
  13912. /*
  13913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13916. */
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13918. // MeterValuesSampledData
  13919. /*
  13920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13923. */
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13925. // MeterValuesSampledDataMaxLength
  13926. /*
  13927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13930. */
  13931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13932. // MeterValueSampleInterval
  13933. /*
  13934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13937. */
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13939. // MinimumStatusDuration
  13940. /*
  13941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13944. */
  13945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13946. // NumberOfConnectors
  13947. /*
  13948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13951. {
  13952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13953. }
  13954. else
  13955. {
  13956. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13957. }
  13958. */
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13960. // ResetRetries
  13961. /*
  13962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13965. */
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13967. // ConnectorPhaseRotation
  13968. /*
  13969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13972. */
  13973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13974. // ConnectorPhaseRotationMaxLength
  13975. /*
  13976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13979. */
  13980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13981. // StopTransactionOnEVSideDisconnect
  13982. /*
  13983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13986. */
  13987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13988. // StopTransactionOnInvalidId
  13989. /*
  13990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13993. */
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13995. // StopTxnAlignedData
  13996. /*
  13997. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14000. */
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14002. // StopTxnAlignedDataMaxLength
  14003. /*
  14004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14007. */
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14009. // StopTxnSampledData
  14010. /*
  14011. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14014. */
  14015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14016. // StopTxnSampledDataMaxLength
  14017. /*
  14018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14021. */
  14022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14023. // SupportedFeatureProfiles
  14024. /*
  14025. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14028. */
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14030. // SupportedFeatureProfilesMaxLength
  14031. /*
  14032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14035. */
  14036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14037. // TransactionMessageAttempts
  14038. /*
  14039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14042. */
  14043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14044. // TransactionMessageRetryInterval
  14045. /*
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14049. */
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14051. // UnlockConnectorOnEVSideDisconnect
  14052. /*
  14053. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14056. */
  14057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14058. // WebSocketPingInterval
  14059. /*
  14060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14063. */
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14065. // QueueOffLineMeterValues
  14066. /*
  14067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14070. */
  14071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14072. // AuthorizationKey
  14073. /*
  14074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14077. */
  14078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14079. // SecurityProfile
  14080. /*
  14081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14084. */
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14086. // DefaultPrice
  14087. /*
  14088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14091. */
  14092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14093. // CustomDisplayCostAndPrice
  14094. /*
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14098. */
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14100. // CustomIdleFeeAfterStop
  14101. /*
  14102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14105. */
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14107. // SystemUptimeSec
  14108. /*
  14109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14112. */
  14113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14114. // FreeVend
  14115. /*
  14116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14119. */
  14120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14121. // OcppServer
  14122. /*
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14126. */
  14127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14128. // MaintainServer
  14129. /*
  14130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14133. */
  14134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14135. // StatusNotificationPeriodically
  14136. /*
  14137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14140. */
  14141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14142. // StatusNotificationInterval
  14143. /*
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14147. */
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14149. // ConfigurationVersion
  14150. /*
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14154. */
  14155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14156. //* Local Auth List Management Profile*/
  14157. //LocalAuthListEnabled
  14158. /*
  14159. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14162. */
  14163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14164. //LocalAuthListMaxLength
  14165. /*
  14166. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14169. */
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14171. //SendLocalListMaxLength
  14172. /*
  14173. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14176. */
  14177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14178. //ReserveConnectorZeroSupported
  14179. /*
  14180. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14183. */
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14185. //* Smart Charging Profile */
  14186. //ChargeProfileMaxStackLevel
  14187. /*
  14188. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14191. */
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14193. // ChargingScheduleAllowedChargingRateUnit
  14194. /*
  14195. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14198. */
  14199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14200. // ChargingScheduleMaxPeriods
  14201. /*
  14202. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14205. */
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14207. // ConnectorSwitch3to1PhaseSupported
  14208. /*
  14209. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14212. */
  14213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14214. // MaxChargingProfilesInstalled
  14215. /*
  14216. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14219. */
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14221. fclose(outfile);
  14222. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14223. }
  14224. void getKeyValue(char *keyReq)
  14225. {
  14226. int isEmpty = FALSE;
  14227. int isKnowKey = FALSE;
  14228. DEBUG_INFO("keyReq = %s\n", keyReq);
  14229. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14230. isEmpty = TRUE;
  14231. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14232. {
  14233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14235. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14236. {
  14237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14238. }
  14239. else
  14240. {
  14241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14242. }
  14243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14244. isKnowKey = TRUE;
  14245. }
  14246. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14247. {
  14248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14250. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14251. {
  14252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14253. }
  14254. else
  14255. {
  14256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14257. }
  14258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14259. isKnowKey = TRUE;
  14260. }
  14261. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14262. {
  14263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14266. {
  14267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14268. }
  14269. else
  14270. {
  14271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14272. }
  14273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14274. isKnowKey = TRUE;
  14275. }
  14276. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14277. {
  14278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14281. {
  14282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14283. }
  14284. else
  14285. {
  14286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14287. }
  14288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14289. isKnowKey = TRUE;
  14290. }
  14291. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14292. {
  14293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14295. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14296. {
  14297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14298. }
  14299. else
  14300. {
  14301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14302. }
  14303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14304. isKnowKey = TRUE;
  14305. }
  14306. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14307. {
  14308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14310. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14311. {
  14312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14313. }
  14314. else
  14315. {
  14316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14317. }
  14318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14319. isKnowKey = TRUE;
  14320. }
  14321. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14322. {
  14323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14325. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14326. {
  14327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14328. }
  14329. else
  14330. {
  14331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14332. }
  14333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14334. isKnowKey = TRUE;
  14335. }
  14336. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14337. {
  14338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14341. {
  14342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14343. }
  14344. else
  14345. {
  14346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14347. }
  14348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14349. isKnowKey = TRUE;
  14350. }
  14351. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14352. {
  14353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14356. {
  14357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14358. }
  14359. else
  14360. {
  14361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14362. }
  14363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14364. isKnowKey = TRUE;
  14365. }
  14366. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14367. {
  14368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14370. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14371. {
  14372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14373. }
  14374. else
  14375. {
  14376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14377. }
  14378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14379. isKnowKey = TRUE;
  14380. }
  14381. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14382. {
  14383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14385. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14386. {
  14387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14388. }
  14389. else
  14390. {
  14391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14392. }
  14393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14394. isKnowKey = TRUE;
  14395. }
  14396. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14397. {
  14398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14401. {
  14402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14403. }
  14404. else
  14405. {
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14407. }
  14408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14409. isKnowKey = TRUE;
  14410. }
  14411. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14412. {
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14415. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14416. {
  14417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14418. }
  14419. else
  14420. {
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14422. }
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14424. isKnowKey = TRUE;
  14425. }
  14426. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14427. {
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14430. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14431. {
  14432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14433. }
  14434. else
  14435. {
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14437. }
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14439. isKnowKey = TRUE;
  14440. }
  14441. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14442. {
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14445. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14446. {
  14447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14448. }
  14449. else
  14450. {
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14452. }
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14454. isKnowKey = TRUE;
  14455. }
  14456. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14457. {
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14461. {
  14462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14463. }
  14464. else
  14465. {
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14467. }
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14469. isKnowKey = TRUE;
  14470. }
  14471. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14472. {
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14475. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14476. {
  14477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14478. }
  14479. else
  14480. {
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14482. }
  14483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14484. isKnowKey = TRUE;
  14485. }
  14486. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14487. {
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14490. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14491. {
  14492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14493. }
  14494. else
  14495. {
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14497. }
  14498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14499. isKnowKey = TRUE;
  14500. }
  14501. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14502. {
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14505. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14506. {
  14507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14508. }
  14509. else
  14510. {
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14512. }
  14513. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14515. isKnowKey = TRUE;
  14516. }
  14517. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14518. {
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14521. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14522. {
  14523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14524. }
  14525. else
  14526. {
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14528. }
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14530. isKnowKey = TRUE;
  14531. }
  14532. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14533. {
  14534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14536. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14537. {
  14538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14539. }
  14540. else
  14541. {
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14543. }
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14545. isKnowKey = TRUE;
  14546. }
  14547. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14548. {
  14549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14551. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14552. {
  14553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14554. }
  14555. else
  14556. {
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14558. }
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14560. isKnowKey = TRUE;
  14561. }
  14562. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14563. {
  14564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14566. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14567. {
  14568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14569. }
  14570. else
  14571. {
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14573. }
  14574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14575. isKnowKey = TRUE;
  14576. }
  14577. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14578. {
  14579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14581. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14582. {
  14583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14584. }
  14585. else
  14586. {
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14588. }
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14590. isKnowKey = TRUE;
  14591. }
  14592. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14593. {
  14594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14596. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14597. {
  14598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14599. }
  14600. else
  14601. {
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14603. }
  14604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14605. isKnowKey = TRUE;
  14606. }
  14607. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14608. {
  14609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14611. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14612. {
  14613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14614. }
  14615. else
  14616. {
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14618. }
  14619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14620. isKnowKey = TRUE;
  14621. }
  14622. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14623. {
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14626. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14627. {
  14628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14629. }
  14630. else
  14631. {
  14632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14633. }
  14634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14635. isKnowKey = TRUE;
  14636. }
  14637. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14638. {
  14639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14642. {
  14643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14644. }
  14645. else
  14646. {
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14648. }
  14649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14650. isKnowKey = TRUE;
  14651. }
  14652. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14653. {
  14654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14656. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14657. {
  14658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14659. }
  14660. else
  14661. {
  14662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14663. }
  14664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14665. isKnowKey = TRUE;
  14666. }
  14667. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14668. {
  14669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14671. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14672. {
  14673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14674. }
  14675. else
  14676. {
  14677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14678. }
  14679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14680. isKnowKey = TRUE;
  14681. }
  14682. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14683. {
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14687. {
  14688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14689. }
  14690. else
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14693. }
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14695. isKnowKey = TRUE;
  14696. }
  14697. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14698. {
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14701. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14702. {
  14703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14704. }
  14705. else
  14706. {
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14708. }
  14709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14710. isKnowKey = TRUE;
  14711. }
  14712. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14713. {
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14716. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14717. {
  14718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14719. }
  14720. else
  14721. {
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14723. }
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14725. isKnowKey = TRUE;
  14726. }
  14727. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14728. {
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14731. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14732. {
  14733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14734. }
  14735. else
  14736. {
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14738. }
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14740. isKnowKey = TRUE;
  14741. }
  14742. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14743. {
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14746. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14747. {
  14748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14749. }
  14750. else
  14751. {
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14753. }
  14754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14755. isKnowKey = TRUE;
  14756. }
  14757. /*
  14758. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14759. {
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14762. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14763. {
  14764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14765. }
  14766. else
  14767. {
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14769. }
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14771. isKnowKey = TRUE;
  14772. }*/
  14773. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14774. {
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14778. {
  14779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14780. }
  14781. else
  14782. {
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14784. }
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14786. isKnowKey = TRUE;
  14787. }
  14788. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14789. {
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14793. {
  14794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14795. }
  14796. else
  14797. {
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14799. }
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14801. isKnowKey = TRUE;
  14802. }
  14803. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14804. {
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14807. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14808. {
  14809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14810. }
  14811. else
  14812. {
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14814. }
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14816. isKnowKey = TRUE;
  14817. }
  14818. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14819. {
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14822. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14823. {
  14824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14825. }
  14826. else
  14827. {
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14829. }
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14831. isKnowKey = TRUE;
  14832. }
  14833. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14834. {
  14835. struct sysinfo s_info;
  14836. int error = sysinfo(&s_info);
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14839. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14840. {
  14841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14842. }
  14843. else
  14844. {
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14846. }
  14847. if(error != 0)
  14848. {
  14849. DEBUG_WARN("System uptime get error: %d\n", error);
  14850. }
  14851. else
  14852. {
  14853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14854. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14855. }
  14856. isKnowKey = TRUE;
  14857. }
  14858. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14859. {
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14862. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14865. }
  14866. else
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14869. }
  14870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14871. isKnowKey = TRUE;
  14872. }
  14873. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14874. {
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14877. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14878. {
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14880. }
  14881. else
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14884. }
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14886. isKnowKey = TRUE;
  14887. }
  14888. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14889. {
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14892. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14893. {
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14895. }
  14896. else
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14899. }
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14901. isKnowKey = TRUE;
  14902. }
  14903. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14904. {
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14908. {
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14910. }
  14911. else
  14912. {
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14914. }
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14916. isKnowKey = TRUE;
  14917. }
  14918. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14919. {
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14922. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14923. {
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14925. }
  14926. else
  14927. {
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14929. }
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14931. isKnowKey = TRUE;
  14932. }
  14933. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14934. {
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14937. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14938. {
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14940. }
  14941. else
  14942. {
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14944. }
  14945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14946. isKnowKey = TRUE;
  14947. }
  14948. #if 1
  14949. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14953. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14956. }
  14957. else
  14958. {
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14960. }
  14961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14962. isKnowKey = TRUE;
  14963. }
  14964. #endif
  14965. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14966. {
  14967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14969. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14970. {
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14972. }
  14973. else
  14974. {
  14975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14976. }
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14978. isKnowKey = TRUE;
  14979. }
  14980. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14981. {
  14982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14984. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14985. {
  14986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14987. }
  14988. else
  14989. {
  14990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14991. }
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14993. isKnowKey = TRUE;
  14994. }
  14995. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14996. {
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14999. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15000. {
  15001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15002. }
  15003. else
  15004. {
  15005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15006. }
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15008. isKnowKey = TRUE;
  15009. }
  15010. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15011. {
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15014. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15015. {
  15016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15017. }
  15018. else
  15019. {
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15021. }
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15023. isKnowKey = TRUE;
  15024. }
  15025. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15026. {
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15029. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15030. {
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15032. }
  15033. else
  15034. {
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15036. }
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15038. isKnowKey = TRUE;
  15039. }
  15040. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15041. {
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15044. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15045. {
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15047. }
  15048. else
  15049. {
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15051. }
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15053. isKnowKey = TRUE;
  15054. }
  15055. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15056. {
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15059. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15060. {
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15062. }
  15063. else
  15064. {
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15066. }
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15068. isKnowKey = TRUE;
  15069. }
  15070. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15074. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15077. }
  15078. else
  15079. {
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15081. }
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15083. isKnowKey = TRUE;
  15084. }
  15085. //=========================================================
  15086. if(!isEmpty && !isKnowKey)
  15087. {
  15088. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15089. strcpy(unknownkey[UnknownKeynum], keyReq);
  15090. UnknownKeynum = UnknownKeynum + 1;
  15091. }
  15092. }
  15093. void processUnkownKey(void)
  15094. {
  15095. DEBUG_INFO("processUnkownKey...\n");
  15096. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15097. for(int index=0; index < UnknownKeynum; index++)
  15098. {
  15099. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15100. {
  15101. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15102. }
  15103. }
  15104. }
  15105. int setKeyValue(char *key, char *value)
  15106. {
  15107. int isSuccess = NotSupported;
  15108. int check_ascii=0;
  15109. char str[501]={0};
  15110. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15111. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15112. {
  15113. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15114. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15115. {
  15116. strcpy(str, (const char*)value);
  15117. for(int i = 0; str[i]; i++){
  15118. str[i] = tolower(str[i]);
  15119. }
  15120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15121. isSuccess = ConfigurationStatus_Accepted;
  15122. }
  15123. else
  15124. {
  15125. isSuccess = ConfigurationStatus_Rejected;
  15126. }
  15127. }
  15128. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15129. {
  15130. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15132. {
  15133. strcpy(str, (const char*)value);
  15134. for(int i = 0; str[i]; i++){
  15135. str[i] = tolower(str[i]);
  15136. }
  15137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15138. isSuccess = ConfigurationStatus_Accepted;
  15139. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15140. }
  15141. else
  15142. {
  15143. isSuccess = ConfigurationStatus_Rejected;
  15144. }
  15145. }
  15146. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15147. {
  15148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15149. {
  15150. strcpy(str, (const char*)value);
  15151. for(int i = 0; str[i]; i++)
  15152. {
  15153. str[i] = tolower(str[i]);
  15154. }
  15155. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15157. isSuccess = ConfigurationStatus_Accepted;
  15158. }
  15159. else
  15160. {
  15161. isSuccess = ConfigurationStatus_Rejected;
  15162. }
  15163. }
  15164. if(strcmp(key, "BlinkRepeat") == 0)
  15165. {
  15166. //Charger.BlinkRepeat = Integer.parseInt(value);
  15167. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15168. {
  15169. check_ascii = value[0];
  15170. if( (check_ascii < 48) || (check_ascii > 57) )
  15171. {
  15172. isSuccess = ConfigurationStatus_Rejected;
  15173. }
  15174. else
  15175. {
  15176. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15177. isSuccess = ConfigurationStatus_Accepted;
  15178. }
  15179. }
  15180. else
  15181. {
  15182. isSuccess = ConfigurationStatus_Rejected;
  15183. }
  15184. }
  15185. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15186. {
  15187. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15188. {
  15189. check_ascii = value[0];
  15190. if( (check_ascii < 48) || (check_ascii > 57) )
  15191. {
  15192. isSuccess = ConfigurationStatus_Rejected;
  15193. }
  15194. else
  15195. {
  15196. if((atoi(value) == 0) || (atoi(value) >= 5))
  15197. {
  15198. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15200. isSuccess = ConfigurationStatus_Accepted;
  15201. }
  15202. else
  15203. isSuccess = ConfigurationStatus_Rejected;
  15204. }
  15205. }
  15206. else
  15207. {
  15208. isSuccess = ConfigurationStatus_Rejected;
  15209. }
  15210. }
  15211. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15212. {
  15213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15214. {
  15215. check_ascii = value[0];
  15216. if( (check_ascii < 48) || (check_ascii > 57) )
  15217. {
  15218. isSuccess = ConfigurationStatus_Rejected;
  15219. }
  15220. else
  15221. {
  15222. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15224. isSuccess = ConfigurationStatus_Accepted;
  15225. }
  15226. }
  15227. else
  15228. {
  15229. isSuccess = ConfigurationStatus_Rejected;
  15230. }
  15231. }
  15232. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15233. {
  15234. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15235. {
  15236. check_ascii = value[0];
  15237. if( (check_ascii < 48) || (check_ascii > 57) )
  15238. {
  15239. isSuccess = ConfigurationStatus_Rejected;
  15240. }
  15241. else
  15242. {
  15243. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15245. isSuccess = ConfigurationStatus_Accepted;
  15246. }
  15247. }
  15248. else
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. }
  15253. if(strcmp(key, "HeartbeatInterval") == 0)
  15254. {
  15255. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15256. {
  15257. check_ascii = value[0];
  15258. if( (check_ascii < 48) || (check_ascii > 57) )
  15259. {
  15260. isSuccess = ConfigurationStatus_Rejected;
  15261. }
  15262. else
  15263. {
  15264. if((atoi(value) == 0) || (atoi(value) >= 10))
  15265. {
  15266. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15268. HeartBeatWaitTime = atoi(value);
  15269. isSuccess = ConfigurationStatus_Accepted;
  15270. }
  15271. else
  15272. {
  15273. isSuccess = ConfigurationStatus_Rejected;
  15274. }
  15275. }
  15276. }
  15277. else
  15278. {
  15279. isSuccess = ConfigurationStatus_Rejected;
  15280. }
  15281. }
  15282. if(strcmp(key, "LightIntensity") == 0)
  15283. {
  15284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15285. {
  15286. check_ascii = value[0];
  15287. if( (check_ascii < 48) || (check_ascii > 57) )
  15288. {
  15289. isSuccess = ConfigurationStatus_Rejected;
  15290. }
  15291. else
  15292. {
  15293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15294. isSuccess = ConfigurationStatus_Accepted;
  15295. }
  15296. }
  15297. else
  15298. {
  15299. isSuccess = ConfigurationStatus_Rejected;
  15300. }
  15301. }
  15302. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15303. {
  15304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15305. {
  15306. strcpy(str, (const char*)value);
  15307. for(int i = 0; str[i]; i++)
  15308. {
  15309. str[i] = tolower(str[i]);
  15310. }
  15311. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15312. isSuccess = ConfigurationStatus_Accepted;
  15313. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15314. }
  15315. else
  15316. {
  15317. isSuccess = ConfigurationStatus_Rejected;
  15318. }
  15319. }
  15320. if(strcmp(key, "LocalPreAuthorize") == 0)
  15321. {
  15322. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15323. {
  15324. strcpy(str, (const char*)value);
  15325. for(int i = 0; str[i]; i++)
  15326. {
  15327. str[i] = tolower(str[i]);
  15328. }
  15329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15330. isSuccess = ConfigurationStatus_Accepted;
  15331. }
  15332. else
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. }
  15337. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15338. {
  15339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15340. {
  15341. check_ascii = value[0];
  15342. if( (check_ascii < 48) || (check_ascii > 57) )
  15343. {
  15344. isSuccess = ConfigurationStatus_Rejected;
  15345. }
  15346. else
  15347. {
  15348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15349. isSuccess = ConfigurationStatus_Accepted;
  15350. }
  15351. }
  15352. else
  15353. {
  15354. isSuccess = ConfigurationStatus_Rejected;
  15355. }
  15356. }
  15357. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15358. {
  15359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15360. {
  15361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15362. isSuccess = ConfigurationStatus_Accepted;
  15363. }
  15364. else
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. }
  15369. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15370. {
  15371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15372. {
  15373. check_ascii = value[0];
  15374. if( (check_ascii < 48) || (check_ascii > 57) )
  15375. {
  15376. isSuccess = ConfigurationStatus_Rejected;
  15377. }
  15378. else
  15379. {
  15380. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15382. isSuccess = ConfigurationStatus_Accepted;
  15383. }
  15384. }
  15385. else
  15386. {
  15387. isSuccess = ConfigurationStatus_Rejected;
  15388. }
  15389. }
  15390. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15391. {
  15392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15393. {
  15394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15395. isSuccess = ConfigurationStatus_Accepted;
  15396. }
  15397. else
  15398. {
  15399. isSuccess = ConfigurationStatus_Rejected;
  15400. }
  15401. }
  15402. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15403. {
  15404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15405. {
  15406. check_ascii = value[0];
  15407. if( (check_ascii < 48) || (check_ascii > 57) )
  15408. {
  15409. isSuccess = ConfigurationStatus_Rejected;
  15410. }
  15411. else
  15412. {
  15413. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15414. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15415. isSuccess = ConfigurationStatus_Accepted;
  15416. }
  15417. }
  15418. else
  15419. {
  15420. isSuccess = ConfigurationStatus_Rejected;
  15421. }
  15422. }
  15423. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15424. {
  15425. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15426. {
  15427. check_ascii = value[0];
  15428. if( (check_ascii < 48) || (check_ascii > 57) )
  15429. {
  15430. isSuccess = ConfigurationStatus_Rejected;
  15431. }
  15432. else
  15433. {
  15434. if((atoi(value) == 0) || (atoi(value) >= 3))
  15435. {
  15436. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15438. isSuccess = ConfigurationStatus_Accepted;
  15439. }
  15440. else
  15441. {
  15442. isSuccess = ConfigurationStatus_Rejected;
  15443. }
  15444. }
  15445. }
  15446. else
  15447. {
  15448. isSuccess = ConfigurationStatus_Rejected;
  15449. }
  15450. }
  15451. if(strcmp(key, "MinimumStatusDuration") == 0)
  15452. {
  15453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15454. {
  15455. check_ascii = value[0];
  15456. if( (check_ascii < 48) || (check_ascii > 57) )
  15457. {
  15458. isSuccess = ConfigurationStatus_Rejected;
  15459. }
  15460. else
  15461. {
  15462. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15463. {
  15464. isSuccess = ConfigurationStatus_Rejected;
  15465. }
  15466. else
  15467. {
  15468. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15470. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15471. isSuccess = ConfigurationStatus_Accepted;
  15472. }
  15473. }
  15474. }
  15475. else
  15476. {
  15477. isSuccess = ConfigurationStatus_Rejected;
  15478. }
  15479. }
  15480. if(strcmp(key, "NumberOfConnectors") == 0)
  15481. {
  15482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15483. {
  15484. check_ascii = value[0];
  15485. if( (check_ascii < 48) || (check_ascii > 57) )
  15486. {
  15487. isSuccess = ConfigurationStatus_Rejected;
  15488. }
  15489. else
  15490. {
  15491. //Charger.ResetRetries = Integer.parseInt(value);
  15492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15493. isSuccess = ConfigurationStatus_Accepted;
  15494. }
  15495. }
  15496. else
  15497. {
  15498. isSuccess = ConfigurationStatus_Rejected;
  15499. }
  15500. }
  15501. if(strcmp(key, "ResetRetries") == 0)
  15502. {
  15503. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15504. {
  15505. check_ascii = value[0];
  15506. if( (check_ascii < 48) || (check_ascii > 57) )
  15507. {
  15508. isSuccess = ConfigurationStatus_Rejected;
  15509. }
  15510. else
  15511. {
  15512. //Charger.ResetRetries = Integer.parseInt(value);
  15513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15514. isSuccess = ConfigurationStatus_Accepted;
  15515. }
  15516. }
  15517. else
  15518. {
  15519. isSuccess = ConfigurationStatus_Rejected;
  15520. }
  15521. }
  15522. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15523. {
  15524. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15525. {
  15526. strcpy(str, (const char*)value);
  15527. for(int i = 0; str[i]; i++)
  15528. {
  15529. str[i] = tolower(str[i]);
  15530. }
  15531. if(strcmp(str, "notapplicable")== 0)
  15532. {
  15533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15534. isSuccess = ConfigurationStatus_Accepted;
  15535. }
  15536. else if(strcmp(str, "unknown")== 0)
  15537. {
  15538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15539. isSuccess = ConfigurationStatus_Accepted;
  15540. }
  15541. else if(strcmp(str, "rst")== 0)
  15542. {
  15543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15544. isSuccess = ConfigurationStatus_Accepted;
  15545. }
  15546. else if(strcmp(str, "rts")== 0)
  15547. {
  15548. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15549. isSuccess = ConfigurationStatus_Accepted;
  15550. }
  15551. else if(strcmp(str, "srt")== 0)
  15552. {
  15553. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15554. isSuccess = ConfigurationStatus_Accepted;
  15555. }
  15556. else if(strcmp(str, "str")== 0)
  15557. {
  15558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15559. isSuccess = ConfigurationStatus_Accepted;
  15560. }
  15561. else if(strcmp(str, "trs")== 0)
  15562. {
  15563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15564. isSuccess = ConfigurationStatus_Accepted;
  15565. }
  15566. else if(strcmp(str, "tsr")== 0)
  15567. {
  15568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15569. isSuccess = ConfigurationStatus_Accepted;
  15570. }
  15571. else
  15572. {
  15573. isSuccess = ConfigurationStatus_Rejected;
  15574. }
  15575. }
  15576. else
  15577. {
  15578. isSuccess = ConfigurationStatus_Rejected;
  15579. }
  15580. }
  15581. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15582. {
  15583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15584. {
  15585. check_ascii = value[0];
  15586. if( (check_ascii < 48) || (check_ascii > 57) )
  15587. {
  15588. isSuccess = ConfigurationStatus_Rejected;
  15589. }
  15590. else
  15591. {
  15592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15593. isSuccess = ConfigurationStatus_Accepted;
  15594. }
  15595. }
  15596. else
  15597. {
  15598. isSuccess = ConfigurationStatus_Rejected;
  15599. }
  15600. }
  15601. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15602. {
  15603. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15604. {
  15605. strcpy(str, (const char*)value);
  15606. for(int i = 0; str[i]; i++)
  15607. {
  15608. str[i] = tolower(str[i]);
  15609. }
  15610. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15612. isSuccess = ConfigurationStatus_Accepted;
  15613. }
  15614. else
  15615. {
  15616. isSuccess = ConfigurationStatus_Rejected;
  15617. }
  15618. }
  15619. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15620. {
  15621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15622. {
  15623. strcpy(str, (const char*)value);
  15624. for(int i = 0; str[i]; i++)
  15625. {
  15626. str[i] = tolower(str[i]);
  15627. }
  15628. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15630. isSuccess = ConfigurationStatus_Accepted;
  15631. }
  15632. else
  15633. {
  15634. isSuccess = ConfigurationStatus_Rejected;
  15635. }
  15636. }
  15637. if(strcmp(key, "StopTxnAlignedData") == 0)
  15638. {
  15639. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15640. {
  15641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15642. isSuccess = ConfigurationStatus_Accepted;
  15643. }
  15644. else
  15645. {
  15646. isSuccess = ConfigurationStatus_Rejected;
  15647. }
  15648. }
  15649. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15650. {
  15651. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15652. {
  15653. check_ascii = value[0];
  15654. if( (check_ascii < 48) || (check_ascii > 57) )
  15655. {
  15656. isSuccess = ConfigurationStatus_Rejected;
  15657. }
  15658. else
  15659. {
  15660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15661. isSuccess = ConfigurationStatus_Accepted;
  15662. }
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. if(strcmp(key, "StopTxnSampledData") == 0)
  15670. {
  15671. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15672. {
  15673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15674. isSuccess = ConfigurationStatus_Accepted;
  15675. }
  15676. else
  15677. {
  15678. isSuccess = ConfigurationStatus_Rejected;
  15679. }
  15680. }
  15681. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15682. {
  15683. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15684. {
  15685. check_ascii = value[0];
  15686. if( (check_ascii < 48) || (check_ascii > 57) )
  15687. {
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. else
  15691. {
  15692. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15693. isSuccess = ConfigurationStatus_Accepted;
  15694. }
  15695. }
  15696. else
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. }
  15701. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15702. {
  15703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15704. {
  15705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. else
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. }
  15713. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15714. {
  15715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15716. {
  15717. check_ascii = value[0];
  15718. if( (check_ascii < 48) || (check_ascii > 57) )
  15719. {
  15720. isSuccess = ConfigurationStatus_Rejected;
  15721. }
  15722. else
  15723. {
  15724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15725. isSuccess = ConfigurationStatus_Accepted;
  15726. }
  15727. }
  15728. else
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. }
  15733. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15734. {
  15735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15736. {
  15737. check_ascii = value[0];
  15738. if( (check_ascii < 48) || (check_ascii > 57) )
  15739. {
  15740. isSuccess = ConfigurationStatus_Rejected;
  15741. }
  15742. else
  15743. {
  15744. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15746. TransactionMessageAttemptsValue = atoi(value);
  15747. isSuccess = ConfigurationStatus_Accepted;
  15748. }
  15749. }
  15750. else
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. }
  15755. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15756. {
  15757. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15758. {
  15759. check_ascii = value[0];
  15760. if( (check_ascii < 48) || (check_ascii > 57) )
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. else
  15765. {
  15766. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15768. TransactionMessageRetryIntervalValue = atoi(value);
  15769. isSuccess = ConfigurationStatus_Accepted;
  15770. }
  15771. }
  15772. else
  15773. {
  15774. isSuccess = ConfigurationStatus_Rejected;
  15775. }
  15776. }
  15777. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15778. {
  15779. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15780. {
  15781. strcpy(str, (const char*)value);
  15782. for(int i = 0; str[i]; i++)
  15783. {
  15784. str[i] = tolower(str[i]);
  15785. }
  15786. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15788. isSuccess = ConfigurationStatus_Accepted;
  15789. }
  15790. else
  15791. {
  15792. isSuccess = ConfigurationStatus_Rejected;
  15793. }
  15794. }
  15795. if(strcmp(key, "WebSocketPingInterval") == 0)
  15796. {
  15797. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15798. {
  15799. check_ascii = value[0];
  15800. if( (check_ascii < 48) || (check_ascii > 57) )
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. else
  15805. {
  15806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15807. isSuccess = ConfigurationStatus_Accepted;
  15808. if((atoi(value) == 0) || (atoi(value) >= 10))
  15809. {
  15810. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15811. isSuccess = ConfigurationStatus_Accepted;
  15812. }
  15813. else
  15814. isSuccess = ConfigurationStatus_Rejected;
  15815. }
  15816. }
  15817. else
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. }
  15822. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15823. {
  15824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15825. {
  15826. strcpy(str, (const char*)value);
  15827. for(int i = 0; str[i]; i++)
  15828. {
  15829. str[i] = tolower(str[i]);
  15830. }
  15831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15832. isSuccess = ConfigurationStatus_Accepted;
  15833. }
  15834. else
  15835. {
  15836. isSuccess = ConfigurationStatus_Rejected;
  15837. }
  15838. }
  15839. if(strcmp(key, "AuthorizationKey") == 0)
  15840. {
  15841. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15842. {
  15843. strcpy(str, (const char*)value);
  15844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15845. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15846. isSuccess = ConfigurationStatus_Accepted;
  15847. }
  15848. else
  15849. {
  15850. isSuccess = ConfigurationStatus_Rejected;
  15851. }
  15852. }
  15853. if(strcmp(key, "SecurityProfile") == 0)
  15854. {
  15855. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15856. {
  15857. check_ascii = value[0];
  15858. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15859. {
  15860. isSuccess = ConfigurationStatus_Rejected;
  15861. }
  15862. else if(check_ascii == 0x33)
  15863. {
  15864. isSuccess = NotSupported;
  15865. }
  15866. else
  15867. {
  15868. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15869. {
  15870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15871. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15872. isSuccess = ConfigurationStatus_Accepted;
  15873. }
  15874. else
  15875. isSuccess = ConfigurationStatus_Rejected;
  15876. }
  15877. }
  15878. else
  15879. {
  15880. isSuccess = ConfigurationStatus_Rejected;
  15881. }
  15882. }
  15883. if(strcmp(key, "DefaultPrice") == 0)
  15884. {
  15885. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15886. {
  15887. strcpy(str, (const char*)value);
  15888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15889. isSuccess = ConfigurationStatus_Accepted;
  15890. }
  15891. else
  15892. {
  15893. isSuccess = ConfigurationStatus_Rejected;
  15894. }
  15895. }
  15896. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15897. {
  15898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15899. {
  15900. strcpy(str, (const char*)value);
  15901. for(int i = 0; str[i]; i++)
  15902. {
  15903. str[i] = tolower(str[i]);
  15904. }
  15905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15906. isSuccess = ConfigurationStatus_Accepted;
  15907. }
  15908. else
  15909. {
  15910. isSuccess = ConfigurationStatus_Rejected;
  15911. }
  15912. }
  15913. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15914. {
  15915. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15916. {
  15917. strcpy(str, (const char*)value);
  15918. for(int i = 0; str[i]; i++)
  15919. {
  15920. str[i] = tolower(str[i]);
  15921. }
  15922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15923. isSuccess = ConfigurationStatus_Accepted;
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "SystemUptimeSec") == 0)
  15931. {
  15932. isSuccess = NotSupported;
  15933. }
  15934. if(strcmp(key, "FreeVend") == 0)
  15935. {
  15936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15937. {
  15938. strcpy(str, (const char*)value);
  15939. for(int i = 0; str[i]; i++)
  15940. {
  15941. str[i] = tolower(str[i]);
  15942. }
  15943. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15944. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15945. isSuccess = ConfigurationStatus_Accepted;
  15946. }
  15947. else
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. }
  15952. if(strcmp(key, "OcppServer") == 0)
  15953. {
  15954. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15955. {
  15956. strcpy(str, (const char*)value);
  15957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15958. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15959. isSuccess = ConfigurationStatus_Accepted;
  15960. }
  15961. else
  15962. {
  15963. isSuccess = ConfigurationStatus_Rejected;
  15964. }
  15965. }
  15966. if(strcmp(key, "MaintainServer") == 0)
  15967. {
  15968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15969. {
  15970. strcpy(str, (const char*)value);
  15971. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15972. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15973. isSuccess = ConfigurationStatus_Accepted;
  15974. }
  15975. else
  15976. {
  15977. isSuccess = ConfigurationStatus_Rejected;
  15978. }
  15979. }
  15980. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  15981. {
  15982. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15983. {
  15984. strcpy(str, (const char*)value);
  15985. for(int i = 0; str[i]; i++)
  15986. {
  15987. str[i] = tolower(str[i]);
  15988. }
  15989. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  15990. isSuccess = ConfigurationStatus_Accepted;
  15991. }
  15992. else
  15993. {
  15994. isSuccess = ConfigurationStatus_Rejected;
  15995. }
  15996. }
  15997. if(strcmp(key, "StatusNotificationInterval") == 0)
  15998. {
  15999. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16000. {
  16001. check_ascii = value[0];
  16002. if( (check_ascii < 48) || (check_ascii > 57) )
  16003. {
  16004. isSuccess = ConfigurationStatus_Rejected;
  16005. }
  16006. else
  16007. {
  16008. if((atoi(value) == 0) || (atoi(value) >= 10))
  16009. {
  16010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16011. isSuccess = ConfigurationStatus_Accepted;
  16012. }
  16013. else
  16014. isSuccess = ConfigurationStatus_Rejected;
  16015. }
  16016. }
  16017. else
  16018. {
  16019. isSuccess = ConfigurationStatus_Rejected;
  16020. }
  16021. }
  16022. #if 0
  16023. //For OCPP Test Case
  16024. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16025. {
  16026. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16027. {
  16028. strcpy(str, (const char*)value);
  16029. for(int i = 0; str[i]; i++)
  16030. {
  16031. str[i] = tolower(str[i]);
  16032. }
  16033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16034. isSuccess = ConfigurationStatus_Accepted;
  16035. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16036. }
  16037. else
  16038. {
  16039. isSuccess = ConfigurationStatus_Rejected;
  16040. }
  16041. }
  16042. #endif
  16043. #if 1
  16044. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16045. {
  16046. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16047. {
  16048. strcpy(str, (const char*)value);
  16049. for(int i = 0; str[i]; i++)
  16050. {
  16051. str[i] = tolower(str[i]);
  16052. }
  16053. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16054. isSuccess = ConfigurationStatus_Accepted;
  16055. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16056. }
  16057. else
  16058. {
  16059. isSuccess = ConfigurationStatus_Rejected;
  16060. }
  16061. }
  16062. #endif
  16063. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16064. {
  16065. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16066. {
  16067. check_ascii = value[0];
  16068. if( (check_ascii < 48) || (check_ascii > 57) )
  16069. {
  16070. isSuccess = ConfigurationStatus_Rejected;
  16071. }
  16072. else
  16073. {
  16074. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16075. isSuccess = ConfigurationStatus_Accepted;
  16076. }
  16077. }
  16078. else
  16079. {
  16080. isSuccess = ConfigurationStatus_Rejected;
  16081. }
  16082. }
  16083. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16084. {
  16085. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16086. {
  16087. check_ascii = value[0];
  16088. if( (check_ascii < 48) || (check_ascii > 57) )
  16089. {
  16090. isSuccess = ConfigurationStatus_Rejected;
  16091. }
  16092. else
  16093. {
  16094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16095. isSuccess = ConfigurationStatus_Accepted;
  16096. }
  16097. }
  16098. else
  16099. {
  16100. isSuccess = ConfigurationStatus_Rejected;
  16101. }
  16102. }
  16103. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16104. {
  16105. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16106. {
  16107. strcpy(str, (const char*)value);
  16108. for(int i = 0; str[i]; i++)
  16109. {
  16110. str[i] = tolower(str[i]);
  16111. }
  16112. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16113. isSuccess = ConfigurationStatus_Accepted;
  16114. }
  16115. else
  16116. {
  16117. isSuccess = ConfigurationStatus_Rejected;
  16118. }
  16119. }
  16120. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16121. {
  16122. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16123. {
  16124. check_ascii = value[0];
  16125. if( (check_ascii < 48) || (check_ascii > 57) )
  16126. {
  16127. isSuccess = ConfigurationStatus_Rejected;
  16128. }
  16129. else
  16130. {
  16131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16132. isSuccess = ConfigurationStatus_Accepted;
  16133. }
  16134. }
  16135. else
  16136. {
  16137. isSuccess = ConfigurationStatus_Rejected;
  16138. }
  16139. }
  16140. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16141. {
  16142. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16143. {
  16144. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16145. isSuccess = ConfigurationStatus_Accepted;
  16146. }
  16147. else
  16148. {
  16149. isSuccess = ConfigurationStatus_Rejected;
  16150. }
  16151. }
  16152. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16153. {
  16154. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16155. {
  16156. check_ascii = value[0];
  16157. if( (check_ascii < 48) || (check_ascii > 57) )
  16158. {
  16159. isSuccess = ConfigurationStatus_Rejected;
  16160. }
  16161. else
  16162. {
  16163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16164. isSuccess = ConfigurationStatus_Accepted;
  16165. }
  16166. }
  16167. else
  16168. {
  16169. isSuccess = ConfigurationStatus_Rejected;
  16170. }
  16171. }
  16172. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16173. {
  16174. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16175. {
  16176. strcpy(str, (const char*)value);
  16177. for(int i = 0; str[i]; i++)
  16178. {
  16179. str[i] = tolower(str[i]);
  16180. }
  16181. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16182. isSuccess = ConfigurationStatus_Accepted;
  16183. }
  16184. else
  16185. {
  16186. isSuccess = ConfigurationStatus_Rejected;
  16187. }
  16188. }
  16189. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16190. {
  16191. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16192. {
  16193. check_ascii = value[0];
  16194. if( (check_ascii < 48) || (check_ascii > 57) )
  16195. {
  16196. isSuccess = ConfigurationStatus_Rejected;
  16197. }
  16198. else
  16199. {
  16200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16201. isSuccess = ConfigurationStatus_Accepted;
  16202. }
  16203. }
  16204. else
  16205. {
  16206. isSuccess = ConfigurationStatus_Rejected;
  16207. }
  16208. }
  16209. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16210. return isSuccess;
  16211. }
  16212. int TransactionMessageAttemptsGet(void)
  16213. {
  16214. return TransactionMessageAttemptsValue;
  16215. }
  16216. int FirstHeartBeatResponse(void)
  16217. {
  16218. return FirstHeartBeat;
  16219. }
  16220. int TransactionMessageRetryIntervalGet(void)
  16221. {
  16222. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16223. }
  16224. int ReadHttpStatus(int sock)
  16225. {
  16226. //char c;
  16227. char buff[1024]="",*ptr=buff+1;
  16228. int bytes_received, status;
  16229. DEBUG_INFO("Begin Response ..\n");
  16230. while((bytes_received = recv(sock, ptr, 1, 0))){
  16231. if(bytes_received==-1){
  16232. perror("ReadHttpStatus");
  16233. exit(1);
  16234. }
  16235. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16236. ptr++;
  16237. }
  16238. *ptr=0;
  16239. ptr=buff+1;
  16240. sscanf(ptr,"%*s %d ", &status);
  16241. DEBUG_INFO("%s\n",ptr);
  16242. DEBUG_INFO("status=%d\n",status);
  16243. DEBUG_INFO("End Response ..\n");
  16244. return (bytes_received>0)?status:0;
  16245. }
  16246. //the only filed that it parsed is 'Content-Length'
  16247. int ParseHeader(int sock)
  16248. {
  16249. //char c;
  16250. char buff[1024]="",*ptr=buff+4;
  16251. int bytes_received;
  16252. DEBUG_INFO("Begin HEADER ..\n");
  16253. while((bytes_received = recv(sock, ptr, 1, 0))){
  16254. if(bytes_received==-1){
  16255. perror("Parse Header");
  16256. exit(1);
  16257. }
  16258. if(
  16259. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16260. (ptr[-1]=='\r') && (*ptr=='\n' )
  16261. ) break;
  16262. ptr++;
  16263. }
  16264. *ptr=0;
  16265. ptr=buff+4;
  16266. //printf("%s",ptr);
  16267. if(bytes_received){
  16268. ptr=strstr(ptr,"Content-Length:");
  16269. if(ptr){
  16270. sscanf(ptr,"%*s %d",&bytes_received);
  16271. }else
  16272. bytes_received=-1; //unknown size
  16273. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16274. }
  16275. DEBUG_INFO("End HEADER ..\n");
  16276. return bytes_received ;
  16277. }
  16278. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16279. {
  16280. int result = TRUE;
  16281. char rmFileCmd[100]={0};
  16282. char FilePath[100]={0};
  16283. char ftpbuf[200];
  16284. int systemresult;
  16285. sprintf(FilePath,"/mnt/%s",filename);
  16286. system("ping 8.8.8.8 &");
  16287. if((access(FilePath,F_OK))!=-1)
  16288. {
  16289. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16290. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16291. system(rmFileCmd);
  16292. }
  16293. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16294. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16295. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16296. systemresult = system(ftpbuf);
  16297. if(systemresult != 0)
  16298. {
  16299. DEBUG_INFO("http DownLoad error!\n");
  16300. result = FALSE;
  16301. }
  16302. system("pkill ping");
  16303. return result;
  16304. }
  16305. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16306. {
  16307. int result = TRUE;
  16308. char rmFileCmd[100]={0};
  16309. char FilePath[100]={0};
  16310. char ftpbuf[200];
  16311. int systemresult;
  16312. sprintf(FilePath,"/mnt/%s",filename);
  16313. system("ping 8.8.8.8 &");
  16314. if((access(FilePath,F_OK))!=-1)
  16315. {
  16316. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16317. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16318. system(rmFileCmd);
  16319. }
  16320. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16321. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16322. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16323. systemresult = system(ftpbuf);
  16324. if(systemresult != 0)
  16325. {
  16326. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16327. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16328. systemresult = system(ftpbuf);
  16329. if(systemresult != 0)
  16330. {
  16331. DEBUG_WARN("wget error!\n");
  16332. result = FALSE;
  16333. }
  16334. }
  16335. system("pkill ping");
  16336. return result;
  16337. }
  16338. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16339. {
  16340. char rmFileCmd[100]={0};
  16341. char FilePath[100]={0};
  16342. char buf[512];
  16343. int systemresult = 0;
  16344. //DEBUG_INFO("filename=%s\n",filename);
  16345. //DEBUG_INFO("url=%s\n",url);
  16346. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16347. if((access(FilePath,F_OK))!=-1)
  16348. {
  16349. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16350. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16351. system(rmFileCmd);
  16352. }
  16353. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16354. if(fp == NULL)
  16355. {
  16356. DEBUG_INFO("log is NULL\n");
  16357. return FALSE;
  16358. }
  16359. else
  16360. {
  16361. fprintf(fp, "%s\n", url);
  16362. fprintf(fp, "%s\n", filename);
  16363. fclose(fp);
  16364. }
  16365. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16366. if(phpFP == NULL)
  16367. {
  16368. DEBUG_INFO("PHP upload fail.\n");
  16369. return FALSE;
  16370. }
  16371. else
  16372. {
  16373. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16374. {
  16375. if(strstr(buf, "result") != NULL)
  16376. {
  16377. sscanf(buf, "result: %d", &systemresult);
  16378. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16379. }
  16380. }
  16381. pclose(phpFP);
  16382. }
  16383. if(systemresult != 1)
  16384. {
  16385. DEBUG_INFO("HTTP upload error!\n");
  16386. return FALSE;
  16387. }
  16388. return TRUE;
  16389. }
  16390. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16391. {
  16392. int result = FALSE;
  16393. char ftpbuf[200];
  16394. int systemresult;
  16395. /*
  16396. // Domaind name transfer to IP address
  16397. struct hostent* server;
  16398. char *IPbuffer;
  16399. server = gethostbyname(location);
  16400. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16401. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16402. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16403. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16404. systemresult = system(ftpbuf);
  16405. if(systemresult != 0)
  16406. {
  16407. DEBUG_INFO("ftpput error!\n");
  16408. }
  16409. else
  16410. {
  16411. result = TRUE;
  16412. DEBUG_INFO("ftpput OK!\n");
  16413. }
  16414. return result;
  16415. }
  16416. int GetOcppServerURL()
  16417. {
  16418. int result = FALSE;
  16419. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16420. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16421. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16422. struct yuarel url;
  16423. char urlStr[512];
  16424. // OCPPPH only
  16425. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16426. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16427. {
  16428. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16429. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16430. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16431. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16432. if(yuarel_parse(&url, urlStr) != -1)
  16433. {
  16434. sprintf(OcppProtocol, "%s", url.scheme);
  16435. sprintf(OcppHost, "%s", url.host);
  16436. if(url.path == NULL)
  16437. OcppTempPath[0] = '\0';
  16438. else
  16439. sprintf(OcppTempPath, "%s", url.path);
  16440. if(url.port == 0)
  16441. {
  16442. if(strcmp(OcppProtocol, "wss") == 0)
  16443. OcppPort = 443;
  16444. else
  16445. OcppPort = 80;
  16446. }
  16447. else
  16448. OcppPort = url.port;
  16449. result = TRUE;
  16450. }
  16451. }
  16452. else
  16453. {
  16454. strcpy(OcppHost,"");
  16455. }
  16456. return result;
  16457. }
  16458. int GetOcppPath()
  16459. {
  16460. int result = FALSE;
  16461. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16462. {
  16463. if(OcppTempPath == NULL)
  16464. {
  16465. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16466. }
  16467. else
  16468. {
  16469. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16470. }
  16471. result = TRUE;
  16472. goto End;
  16473. }
  16474. else
  16475. {
  16476. strcpy(OcppPath,"");
  16477. }
  16478. End:
  16479. return result;
  16480. }
  16481. int GetOcppPort()
  16482. {
  16483. return OcppPort;
  16484. }
  16485. int GetOcppConnStatus(void)
  16486. {
  16487. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16488. }
  16489. void SetOcppConnStatus(uint8_t status)
  16490. {
  16491. ShmOCPP16DataPH->OcppConnStatus = status;
  16492. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16493. }
  16494. int GetHeartBeatWithNOResponse(void)
  16495. {
  16496. return HeartBeatWithNOResponse;
  16497. }
  16498. void SetHeartBeatWithNOResponse(void)
  16499. {
  16500. HeartBeatWithNOResponse = 0;
  16501. }
  16502. void GetStartTransactionIdTag(int gun_index)
  16503. {
  16504. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16505. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16506. }
  16507. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16508. {
  16509. char ch;
  16510. FILE *fptr1;
  16511. int temptransactionId;
  16512. char str[100]={0};
  16513. temptransactionId = 0;
  16514. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16515. {
  16516. DEBUG_INFO("IdTag is empty.\n");
  16517. return temptransactionId;
  16518. }
  16519. /*------ Read the file ----------------*/
  16520. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16521. if (!fptr1)
  16522. {
  16523. DEBUG_INFO("QueueTransactionId file open error.\n");
  16524. //printf(" File not found or unable to open the input file!!\n");
  16525. return temptransactionId;
  16526. }
  16527. ch=fgetc(fptr1);
  16528. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16529. rewind(fptr1);
  16530. if(ch!=EOF)
  16531. {
  16532. // printf("%c",ch);
  16533. while (fgets(str, 100, fptr1) != NULL)
  16534. {
  16535. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16536. if(str[0]=='\0')
  16537. {
  16538. break;
  16539. }
  16540. char *revbuf[8] = {0}; // Variable store string split
  16541. int num = 0;// Quantity after string split
  16542. DEBUG_INFO("Transaction queue data= %s\n", str);
  16543. splitstring(str,",",revbuf,&num); // String split
  16544. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16545. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16546. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16547. DEBUG_INFO("------------------------------\n");
  16548. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16549. {
  16550. if(isStopTransaction)
  16551. {
  16552. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16553. {
  16554. temptransactionId = atoi(revbuf[2]);
  16555. //break;
  16556. }
  16557. }
  16558. else
  16559. {
  16560. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16561. {
  16562. temptransactionId = atoi(revbuf[2]);
  16563. //break;
  16564. }
  16565. }
  16566. }
  16567. }
  16568. }
  16569. else
  16570. DEBUG_INFO("EOF\n");
  16571. fclose(fptr1);
  16572. /*------- End of reading ---------------*/
  16573. return temptransactionId;
  16574. }
  16575. void SetTransactionIdZero(int transactionId)
  16576. {
  16577. char ch;
  16578. FILE *fptr1, *fptr2;
  16579. int temptransactionId = 0;
  16580. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16581. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16582. if (!fptr1)
  16583. {
  16584. //printf(" File not found or unable to open the input file!!\n");
  16585. return ;
  16586. }
  16587. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16588. if (!fptr2)
  16589. {
  16590. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16591. fclose(fptr1);
  16592. return ;
  16593. }
  16594. ch=fgetc(fptr1);
  16595. rewind(fptr1);
  16596. if(ch!=EOF)
  16597. {
  16598. // copy all contents to the temporary file except the specific line
  16599. while (fgets(str, 100, fptr1) != NULL)
  16600. {
  16601. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16602. if(str[0]=='\0')
  16603. {
  16604. break;
  16605. }
  16606. char *revbuf[8] = {0};
  16607. int num = 0;
  16608. strcpy(strtemp, str);
  16609. splitstring(str,",",revbuf,&num);
  16610. if(revbuf[2][0] != '\0')
  16611. {
  16612. temptransactionId = atoi(revbuf[2]);
  16613. if(transactionId != temptransactionId)
  16614. {
  16615. fprintf(fptr2, "%s\n", strtemp);
  16616. }
  16617. }
  16618. }
  16619. }
  16620. fclose(fptr1);
  16621. fclose(fptr2);
  16622. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16623. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16624. /*------ Read the file ----------------*/
  16625. }
  16626. int InternetDisconnect(void)
  16627. {
  16628. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16629. }
  16630. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16631. void storeTempStopTransaction(int gun_index)
  16632. {
  16633. char guid[37]={0};
  16634. int tempIndex = 0;
  16635. char TempStopTransaction[256];
  16636. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16637. DEBUG_INFO("storeTempStopTransaction...\n");
  16638. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16639. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16640. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16641. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16642. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16643. {
  16644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16645. {
  16646. tempIndex = ((gun_index==2) ? 1: 0);
  16647. }
  16648. else
  16649. {
  16650. tempIndex = gun_index;
  16651. }
  16652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16653. {
  16654. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16655. {
  16656. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16657. }
  16658. }// END OF CHAdeMO_QUANTITY
  16659. }
  16660. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16661. {
  16662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16663. {
  16664. tempIndex = ((gun_index==2) ? 1: 0);
  16665. }
  16666. else
  16667. {
  16668. tempIndex = gun_index;
  16669. }
  16670. for (int index = 0; index < CCS_QUANTITY; index++)
  16671. {
  16672. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16673. {
  16674. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16675. }
  16676. }// END OF CCS_QUANTITY
  16677. }
  16678. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16679. {
  16680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16681. {
  16682. tempIndex = ((gun_index==2) ? 1: 0);
  16683. }
  16684. else
  16685. {
  16686. tempIndex = gun_index;
  16687. }
  16688. for (int index = 0; index < GB_QUANTITY; index++)
  16689. {
  16690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16691. {
  16692. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16693. }
  16694. }// END OF GB_QUANTITY
  16695. }
  16696. else if(gunType[gun_index] == GUN_TYPE_DO)
  16697. {
  16698. tempIndex = gun_index;
  16699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16700. {
  16701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16702. {
  16703. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16704. }
  16705. }
  16706. }
  16707. else
  16708. {
  16709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16710. {
  16711. tempIndex = 2;
  16712. }
  16713. else
  16714. {
  16715. tempIndex = gun_index;
  16716. }
  16717. for (int index = 0; index < AC_QUANTITY; index++)
  16718. {
  16719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16720. {
  16721. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16722. }
  16723. }// END OF AC_QUANTITY
  16724. }
  16725. //Stop Transaction Time
  16726. struct timeval tmnow;
  16727. struct tm *tm;
  16728. char buf[28];//, usec_buf[6];
  16729. gettimeofday(&tmnow, NULL);
  16730. time_t t;
  16731. t = time(NULL);
  16732. /*UTC time and date*/
  16733. tm = gmtime(&t);
  16734. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16736. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16738. random_uuid(guid);
  16739. /***********************************transactionData******************************************************/
  16740. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16742. //=================================
  16743. //1. Transaction_Begin
  16744. //=================================
  16745. //============================== Energy.Active.Import.Interval ===========================================
  16746. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16747. {
  16748. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16751. 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*/]);
  16752. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16753. 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))
  16754. {
  16755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16756. }
  16757. else
  16758. {
  16759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16760. }
  16761. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16763. }
  16764. //=================================
  16765. //2. Transaction_End
  16766. //=================================
  16767. //2.1====================================== Current.Import L1 ==============================================
  16768. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16769. {
  16770. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16771. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16772. {
  16773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16774. {
  16775. tempIndex = ((gun_index==2) ? 1: 0);
  16776. }
  16777. else
  16778. {
  16779. tempIndex = gun_index;
  16780. }
  16781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16782. {
  16783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16784. {
  16785. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16786. }
  16787. }// End of for CHAdeMO_QUANTITY
  16788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16789. }
  16790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16791. {
  16792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16793. {
  16794. tempIndex = ((gun_index==2) ? 1: 0);
  16795. }
  16796. else
  16797. {
  16798. tempIndex = gun_index;
  16799. }
  16800. for (int index = 0; index < CCS_QUANTITY; index++)
  16801. {
  16802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16803. {
  16804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16805. }
  16806. }// End of for CCS_QUANTITY
  16807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16808. }
  16809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16810. {
  16811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16812. {
  16813. tempIndex = ((gun_index==2) ? 1: 0);
  16814. }
  16815. else
  16816. {
  16817. tempIndex = gun_index;
  16818. }
  16819. for (int index = 0; index < GB_QUANTITY; index++)
  16820. {
  16821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16822. {
  16823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16824. }
  16825. }// End of for GB_QUANTITY
  16826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16827. }
  16828. else if(gunType[gun_index] == GUN_TYPE_DO)
  16829. {
  16830. tempIndex = gun_index;
  16831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16832. {
  16833. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16834. {
  16835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16836. }
  16837. }
  16838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16839. }
  16840. else
  16841. {
  16842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16843. {
  16844. tempIndex = 2;
  16845. }
  16846. else
  16847. {
  16848. tempIndex = gun_index;
  16849. }
  16850. for (int index = 0; index < AC_QUANTITY; index++)
  16851. {
  16852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16853. {
  16854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16855. }
  16856. }// End of for AC_QUANTITY
  16857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16858. }
  16859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16862. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16865. }
  16866. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16867. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16868. {
  16869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16871. {
  16872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16873. {
  16874. tempIndex = ((gun_index==2) ? 1: 0);
  16875. }
  16876. else
  16877. {
  16878. tempIndex = gun_index;
  16879. }
  16880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16881. {
  16882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16883. {
  16884. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16885. }
  16886. }// END OF CHAdeMO_QUANTITY
  16887. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16888. }
  16889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16890. {
  16891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16892. {
  16893. tempIndex = ((gun_index==2) ? 1: 0);
  16894. }
  16895. else
  16896. {
  16897. tempIndex = gun_index;
  16898. }
  16899. for (int index = 0; index < CCS_QUANTITY; index++)
  16900. {
  16901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16902. {
  16903. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16904. }
  16905. }// END OF CCS_QUANTITY
  16906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16907. }
  16908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16909. {
  16910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16911. {
  16912. tempIndex = ((gun_index==2) ? 1: 0);
  16913. }
  16914. else
  16915. {
  16916. tempIndex = gun_index;
  16917. }
  16918. for (int index = 0; index < GB_QUANTITY; index++)
  16919. {
  16920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16921. {
  16922. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16923. }
  16924. }// END OF GB_QUANTITY
  16925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16926. }
  16927. else if(gunType[gun_index] == GUN_TYPE_DO)
  16928. {
  16929. tempIndex = gun_index;
  16930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16931. {
  16932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16933. {
  16934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16935. }
  16936. }
  16937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16938. }
  16939. else
  16940. {
  16941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16942. {
  16943. tempIndex = 2;
  16944. }
  16945. else
  16946. {
  16947. tempIndex = gun_index;
  16948. }
  16949. for (int index = 0; index < AC_QUANTITY; index++)
  16950. {
  16951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16952. {
  16953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16954. }
  16955. }// END OF AC_QUANTITY
  16956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16957. }
  16958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16961. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16962. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16964. }
  16965. //2.3====================================== Power.Active.Import =========================================
  16966. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16967. {
  16968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16970. {
  16971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16972. {
  16973. tempIndex = ((gun_index==2) ? 1: 0);
  16974. }
  16975. else
  16976. {
  16977. tempIndex = gun_index;
  16978. }
  16979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16980. {
  16981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16982. {
  16983. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16984. }
  16985. } // End for CHAdeMO_QUANTITY
  16986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16987. }
  16988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16989. {
  16990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16991. {
  16992. tempIndex = ((gun_index==2) ? 1: 0);
  16993. }
  16994. else
  16995. {
  16996. tempIndex = gun_index;
  16997. }
  16998. for (int index = 0; index < CCS_QUANTITY; index++)
  16999. {
  17000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17001. {
  17002. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17003. }
  17004. } // END for CCS_QUANTITY
  17005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17006. }
  17007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17008. {
  17009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17010. {
  17011. tempIndex = ((gun_index==2) ? 1: 0);
  17012. }
  17013. else
  17014. {
  17015. tempIndex = gun_index;
  17016. }
  17017. for (int index = 0; index < GB_QUANTITY; index++)
  17018. {
  17019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17020. {
  17021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17022. }
  17023. }// END for GB_QUANTITY
  17024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17025. }
  17026. else if(gunType[gun_index] == GUN_TYPE_DO)
  17027. {
  17028. tempIndex = gun_index;
  17029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17030. {
  17031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17032. {
  17033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17034. }
  17035. }
  17036. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17037. }
  17038. else
  17039. {
  17040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17041. {
  17042. tempIndex = 2;
  17043. }
  17044. else
  17045. {
  17046. tempIndex = gun_index;
  17047. }
  17048. for (int index = 0; index < AC_QUANTITY; index++)
  17049. {
  17050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17051. {
  17052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17053. }
  17054. } // END for AC_QUANTITY
  17055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17056. }
  17057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17060. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17063. }
  17064. //2.4====================================== Voltage L1 ====================================================
  17065. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17066. {
  17067. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17068. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17069. {
  17070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17071. {
  17072. tempIndex = ((gun_index==2) ? 1: 0);
  17073. }
  17074. else
  17075. {
  17076. tempIndex = gun_index;
  17077. }
  17078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17079. {
  17080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17081. {
  17082. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17083. }
  17084. } // END OF FOR CHAdeMO_QUANTITY
  17085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17086. }
  17087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17088. {
  17089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17090. {
  17091. tempIndex = ((gun_index==2) ? 1: 0);
  17092. }
  17093. else
  17094. {
  17095. tempIndex = gun_index;
  17096. }
  17097. for (int index = 0; index < CCS_QUANTITY; index++)
  17098. {
  17099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17100. {
  17101. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17102. }
  17103. } // END OF FOR CCS_QUANTITY
  17104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17105. }
  17106. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17107. {
  17108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17109. {
  17110. tempIndex = ((gun_index==2) ? 1: 0);
  17111. }
  17112. else
  17113. {
  17114. tempIndex = gun_index;
  17115. }
  17116. for (int index = 0; index < GB_QUANTITY; index++)
  17117. {
  17118. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17119. {
  17120. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17121. }
  17122. } // END OF FOR GB_QUANTITY
  17123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17124. }
  17125. else if(gunType[gun_index] == GUN_TYPE_DO)
  17126. {
  17127. tempIndex = gun_index;
  17128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17129. {
  17130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17131. {
  17132. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17133. }
  17134. }
  17135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17136. }
  17137. else
  17138. {
  17139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17140. {
  17141. tempIndex = 2;
  17142. }
  17143. else
  17144. {
  17145. tempIndex = gun_index;
  17146. }
  17147. for (int index = 0; index < AC_QUANTITY; index++)
  17148. {
  17149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17150. {
  17151. 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
  17152. }
  17153. } // END OF FOR AC_QUANTITY
  17154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17155. }
  17156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17159. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17162. }
  17163. //2.5============================================== End SoC =========================================================
  17164. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17165. {
  17166. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17167. 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))
  17168. {
  17169. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17170. {
  17171. tempIndex = ((gun_index==2) ? 1: 0);
  17172. }
  17173. else
  17174. {
  17175. tempIndex = gun_index;
  17176. }
  17177. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17178. {
  17179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17180. {
  17181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17182. {
  17183. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17184. }
  17185. }
  17186. }
  17187. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17188. {
  17189. for (int index = 0; index < CCS_QUANTITY; index++)
  17190. {
  17191. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17192. {
  17193. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17194. }
  17195. }
  17196. }
  17197. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17198. {
  17199. for (int index = 0; index < GB_QUANTITY; index++)
  17200. {
  17201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17202. {
  17203. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17204. }
  17205. }
  17206. }
  17207. else if(gunType[gun_index] == GUN_TYPE_DO)
  17208. {
  17209. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17210. {
  17211. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17212. {
  17213. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17214. }
  17215. }
  17216. }
  17217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17222. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17223. } // END FOR DC CASE
  17224. }
  17225. //2.6====================================== Current.Import L2 ==============================================
  17226. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17227. {
  17228. // AC 3 phase L2 current
  17229. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17230. {
  17231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17232. {
  17233. tempIndex = 2;
  17234. }
  17235. else
  17236. {
  17237. tempIndex = gun_index;
  17238. }
  17239. for (int index = 0; index < AC_QUANTITY; index++)
  17240. {
  17241. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17242. {
  17243. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17244. }
  17245. }// End of for AC_QUANTITY
  17246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17247. }
  17248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17251. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17253. }
  17254. //2.7====================================== Current.Import L3 ==============================================
  17255. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17256. {
  17257. // AC 3 phase L3 current
  17258. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17259. {
  17260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17261. {
  17262. tempIndex = 2;
  17263. }
  17264. else
  17265. {
  17266. tempIndex = gun_index;
  17267. }
  17268. for (int index = 0; index < AC_QUANTITY; index++)
  17269. {
  17270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17271. {
  17272. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17273. }
  17274. }// End of for AC_QUANTITY
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17276. }
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17282. }
  17283. //2.9====================================== Voltage L2 ====================================================
  17284. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17285. {
  17286. // AC 3 phase L2 volatge
  17287. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17288. {
  17289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17290. {
  17291. tempIndex = 2;
  17292. }
  17293. else
  17294. {
  17295. tempIndex = gun_index;
  17296. }
  17297. for (int index = 0; index < AC_QUANTITY; index++)
  17298. {
  17299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17300. {
  17301. 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
  17302. }
  17303. } // END OF FOR AC_QUANTITY
  17304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17305. }
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17311. }
  17312. //2.10====================================== Voltage L3 ====================================================
  17313. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17314. {
  17315. // AC 3 phase L3 volatge
  17316. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17317. {
  17318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17319. {
  17320. tempIndex = 2;
  17321. }
  17322. else
  17323. {
  17324. tempIndex = gun_index;
  17325. }
  17326. for (int index = 0; index < AC_QUANTITY; index++)
  17327. {
  17328. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17329. {
  17330. 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
  17331. }
  17332. } // END OF FOR AC_QUANTITY
  17333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17334. }
  17335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17337. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17338. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17339. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17340. }
  17341. //====================== Start SoC ================================
  17342. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17343. {
  17344. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17345. 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))
  17346. {
  17347. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17348. {
  17349. tempIndex = ((gun_index==2) ? 1: 0);
  17350. }
  17351. else
  17352. {
  17353. tempIndex = gun_index;
  17354. }
  17355. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17356. {
  17357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17358. {
  17359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17360. {
  17361. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17362. }
  17363. }
  17364. }
  17365. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17366. {
  17367. for (int index = 0; index < CCS_QUANTITY; index++)
  17368. {
  17369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17370. {
  17371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17372. }
  17373. }
  17374. }
  17375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17376. {
  17377. for (int index = 0; index < GB_QUANTITY; index++)
  17378. {
  17379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17380. {
  17381. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17382. }
  17383. }
  17384. }
  17385. else if(gunType[gun_index] == GUN_TYPE_DO)
  17386. {
  17387. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17388. {
  17389. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17390. {
  17391. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17392. }
  17393. }
  17394. }
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17399. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17401. } // END FOR DC CASE
  17402. }
  17403. //======================================== Message create ==============================================
  17404. json_object *StopTransaction = json_object_new_object();
  17405. json_object *transactionDatas = json_object_new_array();
  17406. json_object *sampledValues = json_object_new_array();
  17407. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17408. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17409. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17410. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17411. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17412. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17413. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17414. {
  17415. json_object *transactionData = json_object_new_object();
  17416. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17417. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17418. {
  17419. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17420. {
  17421. json_object *sampledValue = json_object_new_object();
  17422. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17423. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17424. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17425. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17426. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17427. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17428. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17429. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17430. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17431. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17432. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17433. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17434. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17435. json_object_array_add(sampledValues, sampledValue);
  17436. }
  17437. }
  17438. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17439. json_object_array_add(transactionDatas, transactionData);
  17440. }
  17441. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17442. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17443. ,MESSAGE_TYPE_CALL
  17444. ,guid
  17445. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17446. json_object_put(StopTransaction);
  17447. // Check File "TempStopTransaction" Exist
  17448. if((access(TempStopTransaction,F_OK))!=-1)
  17449. {
  17450. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17451. fclose(fopen(TempStopTransaction, "w"));
  17452. }
  17453. else
  17454. {
  17455. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17456. FILE *log = fopen(TempStopTransaction, "w+");
  17457. if(log == NULL)
  17458. {
  17459. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17460. return ;
  17461. }
  17462. else
  17463. {
  17464. fclose(log);
  17465. }
  17466. }
  17467. //Add TempStopTransaction | Update TempStopTransaction
  17468. // open file for writing
  17469. FILE *outfile;
  17470. outfile = fopen (TempStopTransaction, "a");
  17471. //DEBUG_INFO("data = %s\n", queuedata);
  17472. fputs(queuedata, outfile);
  17473. fputs("\n", outfile);
  17474. fclose (outfile);
  17475. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17476. }
  17477. void checkTempStopTransaction(int gun_index)
  17478. {
  17479. FILE *fptr1;
  17480. char ch;
  17481. char str[QUEUE_MESSAGE_LENGTH]={0};
  17482. char guid[37]={0};
  17483. char tempdata[65]={0};
  17484. char connectorStr[2]={0};
  17485. char TempStopTransaction[256];
  17486. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17487. fptr1 = fopen(TempStopTransaction, "r");
  17488. //TempStopTransaction格式: 槍號,StopTransaction封包
  17489. if (!fptr1)
  17490. {
  17491. //printf(" File not found or unable to open the input file!!\n");
  17492. return ;
  17493. }
  17494. ch=fgetc(fptr1);
  17495. //printf(" Now the content of the file %s is : \n",fname);
  17496. rewind(fptr1);
  17497. if(ch!=EOF)
  17498. {
  17499. // copy all contents to the temporary file except the specific line
  17500. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17501. {
  17502. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17503. if(str[0]=='\0')
  17504. {
  17505. break;
  17506. }
  17507. //TempStopTransaction格式: 槍號,StopTransaction封包
  17508. strncpy(connectorStr, str, 1);
  17509. if(atoi(connectorStr) != (gun_index+1))
  17510. {
  17511. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17512. fclose(fptr1);
  17513. return ;
  17514. }
  17515. //random_uuid(guid);
  17516. strncpy(guid, str+6, 36); //copy guid
  17517. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17518. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17519. {
  17520. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17521. }
  17522. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17523. OCPP_insert_transaction_msg(NO, str);
  17524. memset(str,0,ARRAY_SIZE(str));
  17525. }
  17526. }
  17527. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17528. fclose(fptr1);
  17529. remove(TempStopTransaction); // remove the original file
  17530. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17531. }
  17532. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17533. {
  17534. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17535. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17536. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17537. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17538. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17539. }
  17540. int GetWebSocketPingInterval(void)
  17541. {
  17542. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17543. }
  17544. int GetServerSign(void)
  17545. {
  17546. return server_sign;
  17547. }
  17548. uint8_t GetOcppSecurityProfile()
  17549. {
  17550. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17551. }
  17552. void GetOcppChargerBoxId(uint8_t *data)
  17553. {
  17554. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17555. }
  17556. void GetOcppSecurityPassword(uint8_t *data)
  17557. {
  17558. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17559. }
  17560. void SetOcppVersion(uint8_t *version)
  17561. {
  17562. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17563. DEBUG_INFO("ocpp version: %s\n", version);
  17564. if(strstr((char*)version, "ocpp1.6") != NULL)
  17565. {
  17566. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17567. }
  17568. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17569. {
  17570. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17571. system("pkill OcppBackend");
  17572. }
  17573. }
  17574. void SetServerSign(int value)
  17575. {
  17576. server_sign = value;
  17577. }
  17578. int GetBootNotificationInterval(void)
  17579. {
  17580. return BootNotificationInterval;
  17581. }
  17582. int GetInternetConn(void)
  17583. {
  17584. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17585. }
  17586. int GetBackendConnectionTimeout(void)
  17587. {
  17588. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17589. }
  17590. int isConnectorInitMode(int gun_index)
  17591. {
  17592. int tempIndex = 0;
  17593. int result = TRUE;
  17594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17596. {
  17597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17598. {
  17599. tempIndex = ((gun_index==2) ? 1: 0);
  17600. }
  17601. else
  17602. {
  17603. tempIndex = gun_index;
  17604. }
  17605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17606. {
  17607. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17608. {
  17609. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17610. } //end of the same index
  17611. }//end of for CHAdeMO_QUANTITY
  17612. }
  17613. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17614. {
  17615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17616. {
  17617. tempIndex = ((gun_index==2) ? 1: 0);
  17618. }
  17619. else
  17620. {
  17621. tempIndex = gun_index;
  17622. }
  17623. for (int index = 0; index < CCS_QUANTITY; index++)
  17624. {
  17625. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17626. {
  17627. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17628. } //end of the same index
  17629. } // end of for CCS_QUANTITY
  17630. }
  17631. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17632. {
  17633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17634. {
  17635. tempIndex = ((gun_index==2) ? 1: 0);
  17636. }
  17637. else
  17638. {
  17639. tempIndex = gun_index;
  17640. }
  17641. for (int index = 0; index < GB_QUANTITY; index++)
  17642. {
  17643. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17644. {
  17645. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17646. } //end of the same index
  17647. } // end of for GB_QUANTITY
  17648. }
  17649. else if(gunType[gun_index] == GUN_TYPE_DO)
  17650. {
  17651. tempIndex = gun_index;
  17652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17653. {
  17654. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17655. {
  17656. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17657. } //end of the same index
  17658. }
  17659. }
  17660. else
  17661. {
  17662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17663. {
  17664. tempIndex = 2;
  17665. }
  17666. else
  17667. {
  17668. tempIndex = gun_index;
  17669. }
  17670. for (int index = 0; index < AC_QUANTITY; index++)
  17671. {
  17672. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17673. {
  17674. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17675. }//end of the same index
  17676. }//end of for AC_QUANTITY
  17677. }
  17678. return result;
  17679. }
  17680. void refreshProcDogTimer()
  17681. {
  17682. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17683. }
  17684. void InitialSystemValue(void)
  17685. {
  17686. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17687. locallistVersion=0;
  17688. BootNotificationInterval = 0;
  17689. authorizeRetryTimes = 0;
  17690. GunStatusInterval = 10;
  17691. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17692. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17693. //Hear Beat
  17694. HeartBeatWithNOResponse = 0;
  17695. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17696. FirstHeartBeat = 0;
  17697. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17698. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17699. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17700. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17701. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17702. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17703. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17704. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17705. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17706. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17707. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17708. //Status && ConnectorPlugIn Setting
  17709. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17710. {
  17711. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17712. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17713. }
  17714. for (int index = 0; index < CCS_QUANTITY; index++)
  17715. {
  17716. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17717. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17718. }
  17719. for (int index = 0; index < GB_QUANTITY; index++)
  17720. {
  17721. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17722. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17723. }
  17724. for (int index = 0; index < AC_QUANTITY; index++)
  17725. {
  17726. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17727. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17728. }
  17729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17730. {
  17731. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17732. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17733. }
  17734. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17735. {
  17736. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17737. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17738. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17739. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17740. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17741. }
  17742. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17743. refreshStartTimer(&clientTime.Heartbeat);
  17744. sleep(1);
  17745. }
  17746. void LWS_Send(char *str)
  17747. {
  17748. //=====================================================
  17749. // Check InternetConn 0: disconnected, 1: connected
  17750. //====================================================
  17751. if(GetOcppConnStatus() == 0)
  17752. {
  17753. DEBUG_INFO("offline now !!!\n");
  17754. return;
  17755. }
  17756. // Only disable isWebsocketSendable operation initiated by charger
  17757. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17758. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17759. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17760. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17761. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17762. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17763. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17764. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17765. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17766. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17767. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17768. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17769. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17770. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17771. {
  17772. isWebsocketSendable = 0;
  17773. }
  17774. pthread_mutex_lock(&lock_send);
  17775. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17776. sprintf((char *)SendBuffer, "%s", str);
  17777. SendBufLen = strlen(str);
  17778. pthread_mutex_unlock(&lock_send);
  17779. lws_callback_on_writable(wsi_client);
  17780. //lws_service(context, 0);
  17781. //sleep(1);
  17782. }
  17783. void LWS_SendNow(char *str)
  17784. {
  17785. //=====================================================
  17786. // Check InternetConn 0: disconnected, 1: connected
  17787. //====================================================
  17788. if(GetOcppConnStatus() == 0)
  17789. {
  17790. DEBUG_INFO("offline now !!!\n");
  17791. return;
  17792. }
  17793. // Only disable isWebsocketSendable operation initiated by charger
  17794. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17795. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17796. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17797. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17798. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17799. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17800. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17801. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17802. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17803. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17804. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17805. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17806. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17807. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17808. {
  17809. isWebsocketSendable = 0;
  17810. }
  17811. pthread_mutex_lock(&lock_send);
  17812. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17813. sprintf((char *)SendBuffer, "%s", str);
  17814. SendBufLen = strlen(str);
  17815. pthread_mutex_unlock(&lock_send);
  17816. lws_callback_on_writable(wsi_client);
  17817. lws_service(context, 0);
  17818. //sleep(1);
  17819. }