MessageHandler.c 946 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //=============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. extern sqlite3 *db;
  91. int TransactionMessageAttemptsGet(void);
  92. int TransactionMessageRetryIntervalGet(void);
  93. int GetOcppConnStatus(void);
  94. void SetOcppConnStatus(uint8_t status);
  95. int setKeyValue(char *key, char *value);
  96. void OCPP_get_TableAuthlocalAllData(void);
  97. void processUnkownKey(void);
  98. struct InterLock
  99. {
  100. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  101. unsigned char isGetDiagnosticGoing:1;
  102. unsigned char isUpdateFirmwareGoing:1;
  103. }interLock;
  104. struct ClientTime
  105. {
  106. struct timespec Heartbeat;
  107. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  108. struct timespec StartTransaction;
  109. struct timespec StopTransaction;
  110. struct timespec MeterValues[CONNECTOR_QUANTITY];
  111. struct timespec RemoteStartWait;
  112. struct timespec TcciQueryDeduct;
  113. }clientTime;
  114. typedef union
  115. {
  116. //Operations Initiated by Central System
  117. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  118. struct
  119. {
  120. //CsMsgValue[0]
  121. unsigned char StatusNotificationReq:1; //bit 0,
  122. unsigned char StatusNotificationConf:1; //bit 1,
  123. unsigned char TriggerMeterValue:1; //bit 2,
  124. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  125. unsigned char isOnCharging:1; //bit 4.
  126. unsigned char :3; //bit 5~7
  127. }bits[CONNECTOR_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  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, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  759. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  760. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  761. }
  762. //==========================================
  763. // Check time passed since today
  764. //==========================================
  765. long long DiffTimebWithNow(struct timeb ST)
  766. {
  767. //return milli-second
  768. struct timeb ET;
  769. long long StartTime,StopTime;
  770. ftime(&ET);
  771. StartTime=(long long)ST.time;
  772. StopTime=(long long)ET.time;
  773. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  774. }
  775. int getTimePassSinceToday(uint8_t gun_index)
  776. {
  777. int result = -1;
  778. static time_t lastTime[4];
  779. time_t t;
  780. struct tm *tmStartToday;
  781. struct timeb tbStartToday;
  782. t=time(NULL);
  783. if(difftime(t, lastTime[gun_index])>0)
  784. {
  785. tmStartToday=localtime(&t);
  786. tmStartToday->tm_hour = 0;
  787. tmStartToday->tm_min = 0;
  788. tmStartToday->tm_sec = 0;
  789. tbStartToday.time = mktime(tmStartToday);
  790. tbStartToday.millitm = 0;
  791. result = DiffTimebWithNow(tbStartToday)/1000;
  792. lastTime[gun_index] = t;
  793. }
  794. return result;
  795. }
  796. void getNowDatetime(uint8_t *data)
  797. {
  798. time_t t = time(NULL);
  799. struct tm tm = *localtime(&t);
  800. 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);
  801. }
  802. int syncDateTimeRTC(uint8_t *data)
  803. {
  804. struct ParsingResult
  805. {
  806. int result;
  807. int scanedElement;
  808. int year;
  809. int month;
  810. int mday;
  811. int hour;
  812. int min;
  813. int sec;
  814. int tz_hour;
  815. int tz_min;
  816. float minSec;
  817. }result;
  818. struct tm tmOrg;
  819. struct tm *tmTarget;
  820. struct timeb tbTarget;
  821. char buf[128];
  822. memset(&result, 0x00, sizeof(struct ParsingResult));
  823. result.result = PASS;
  824. if(strstr((char*)data, ".") != NULL)
  825. {
  826. // Original data with 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:%d.%fZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec,
  837. &result.minSec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.minSec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. else
  855. {
  856. // Original data without mini second
  857. if(strstr((char*)data, "Z") != NULL)
  858. {
  859. // Original data with Z
  860. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  861. &result.year,
  862. &result.month,
  863. &result.mday,
  864. &result.hour,
  865. &result.min,
  866. &result.sec);
  867. }
  868. else
  869. {
  870. // Original data without Z
  871. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  872. &result.year,
  873. &result.month,
  874. &result.mday,
  875. &result.hour,
  876. &result.min,
  877. &result.sec,
  878. &result.tz_hour,
  879. &result.tz_min);
  880. }
  881. }
  882. tmOrg.tm_year = result.year - 1900;
  883. tmOrg.tm_mon = result.month - 1;
  884. tmOrg.tm_mday = result.mday;
  885. tmOrg.tm_hour = result.hour;
  886. tmOrg.tm_min = result.min;
  887. tmOrg.tm_sec = result.sec;
  888. tmOrg.tm_gmtoff = 0;
  889. tbTarget.time = mktime(&tmOrg);
  890. tbTarget.timezone = 0;
  891. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  892. tmTarget = gmtime(&tbTarget.time);
  893. 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);
  894. //DEBUG_INFO(" org date time: %s\n", data);
  895. //DEBUG_INFO("parse date time: %s\n", buf);
  896. system(buf);
  897. system("/sbin/hwclock -w --systohc");
  898. if(result.scanedElement < 6)
  899. result.result = FAIL;
  900. return result.result;
  901. }
  902. //==========================================
  903. // GetCompositeSchedule logic related function
  904. //==========================================
  905. int DiffTimebSec(struct timeb ST, struct timeb ET)
  906. {
  907. //return milli-second
  908. unsigned int StartTime,StopTime;
  909. StartTime=(unsigned int)ST.time;
  910. StopTime=(unsigned int)ET.time;
  911. return (StopTime-StartTime);
  912. }
  913. int DiffTimebWithNowSec(struct timeb ST)
  914. {
  915. //return milli-second
  916. struct timeb ET;
  917. unsigned int StartTime,StopTime;
  918. ftime(&ET);
  919. StartTime=(unsigned int)ST.time;
  920. StopTime=(unsigned int)ET.time;
  921. return (StopTime-StartTime);
  922. }
  923. int getStartStop(uint8_t *start, uint8_t *stop)
  924. {
  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. };
  939. struct ParsingResult parseStart;
  940. struct ParsingResult parseStop;
  941. int result = -1;
  942. struct tm tmStart;
  943. struct timeb tbStart;
  944. struct tm tmStop;
  945. struct timeb tbStop;
  946. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  947. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  948. // Scan start & stop date time
  949. if(strstr((char*)start, ".") != NULL)
  950. {
  951. // Original data with mini second
  952. if(strstr((char*)start, "Z") != NULL)
  953. {
  954. // Original data with Z
  955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  956. &parseStart.year,
  957. &parseStart.month,
  958. &parseStart.mday,
  959. &parseStart.hour,
  960. &parseStart.min,
  961. &parseStart.sec,
  962. &parseStart.minSec);
  963. }
  964. else
  965. {
  966. // Original data without Z
  967. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  968. &parseStart.year,
  969. &parseStart.month,
  970. &parseStart.mday,
  971. &parseStart.hour,
  972. &parseStart.min,
  973. &parseStart.sec,
  974. &parseStart.minSec,
  975. &parseStart.tz_hour,
  976. &parseStart.tz_min);
  977. }
  978. }
  979. else
  980. {
  981. // Original data without mini second
  982. if(strstr((char*)start, "Z") != NULL)
  983. {
  984. // Original data with Z
  985. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  986. &parseStart.year,
  987. &parseStart.month,
  988. &parseStart.mday,
  989. &parseStart.hour,
  990. &parseStart.min,
  991. &parseStart.sec);
  992. }
  993. else
  994. {
  995. // Original data without Z
  996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  997. &parseStart.year,
  998. &parseStart.month,
  999. &parseStart.mday,
  1000. &parseStart.hour,
  1001. &parseStart.min,
  1002. &parseStart.sec,
  1003. &parseStart.tz_hour,
  1004. &parseStart.tz_min);
  1005. }
  1006. }
  1007. if(strstr((char*)stop, ".") != NULL)
  1008. {
  1009. // Original data with mini second
  1010. if(strstr((char*)stop, "Z") != NULL)
  1011. {
  1012. // Original data with Z
  1013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1014. &parseStop.year,
  1015. &parseStop.month,
  1016. &parseStop.mday,
  1017. &parseStop.hour,
  1018. &parseStop.min,
  1019. &parseStop.sec,
  1020. &parseStop.minSec);
  1021. }
  1022. else
  1023. {
  1024. // Original data without Z
  1025. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1026. &parseStop.year,
  1027. &parseStop.month,
  1028. &parseStop.mday,
  1029. &parseStop.hour,
  1030. &parseStop.min,
  1031. &parseStop.sec,
  1032. &parseStop.minSec,
  1033. &parseStop.tz_hour,
  1034. &parseStop.tz_min);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // Original data without mini second
  1040. if(strstr((char*)stop, "Z") != NULL)
  1041. {
  1042. // Original data with Z
  1043. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1044. &parseStop.year,
  1045. &parseStop.month,
  1046. &parseStop.mday,
  1047. &parseStop.hour,
  1048. &parseStop.min,
  1049. &parseStop.sec);
  1050. }
  1051. else
  1052. {
  1053. // Original data without Z
  1054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1055. &parseStop.year,
  1056. &parseStop.month,
  1057. &parseStop.mday,
  1058. &parseStop.hour,
  1059. &parseStop.min,
  1060. &parseStop.sec,
  1061. &parseStop.tz_hour,
  1062. &parseStop.tz_min);
  1063. }
  1064. }
  1065. // Calculate date time difference
  1066. if((parseStart.scanedElement >=6) &&
  1067. (parseStop.scanedElement >=6))
  1068. {
  1069. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1070. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1071. tmStart.tm_year = parseStart.year - 1900;
  1072. tmStart.tm_mon = parseStart.month - 1;
  1073. tmStart.tm_mday = parseStart.mday;
  1074. tmStart.tm_hour = parseStart.hour;
  1075. tmStart.tm_min = parseStart.min;
  1076. tmStart.tm_sec = parseStart.sec;
  1077. tmStart.tm_gmtoff = 0;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.timezone = 0;
  1080. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1081. tmStop.tm_year = parseStop.year - 1900;
  1082. tmStop.tm_mon = parseStop.month - 1;
  1083. tmStop.tm_mday = parseStop.mday;
  1084. tmStop.tm_hour = parseStop.hour;
  1085. tmStop.tm_min = parseStop.min;
  1086. tmStop.tm_sec = parseStop.sec;
  1087. tmStop.tm_gmtoff = 0;
  1088. tbStop.time = mktime(&tmStop);
  1089. tbStop.timezone = 0;
  1090. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1091. result = DiffTimebSec(tbStart, tbStop);
  1092. //DEBUG_INFO("getStartStop(): %d\n", result);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1097. }
  1098. return result;
  1099. }
  1100. int isOvertNow(uint8_t *start)
  1101. {
  1102. int result = NO;
  1103. struct ParsingResult
  1104. {
  1105. int result;
  1106. int scanedElement;
  1107. int year;
  1108. int month;
  1109. int mday;
  1110. int hour;
  1111. int min;
  1112. int sec;
  1113. int tz_hour;
  1114. int tz_min;
  1115. float minSec;
  1116. }parsingResult;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. if(strstr((char*)start, ".") != NULL)
  1120. {
  1121. // Original data with mini second
  1122. if(strstr((char*)start, "Z") != NULL)
  1123. {
  1124. // Original data with Z
  1125. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1126. &parsingResult.year,
  1127. &parsingResult.month,
  1128. &parsingResult.mday,
  1129. &parsingResult.hour,
  1130. &parsingResult.min,
  1131. &parsingResult.sec,
  1132. &parsingResult.minSec);
  1133. }
  1134. else
  1135. {
  1136. // Original data without Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec,
  1145. &parsingResult.tz_hour,
  1146. &parsingResult.tz_min);
  1147. }
  1148. }
  1149. else
  1150. {
  1151. // Original data without mini second
  1152. if(strstr((char*)start, "Z") != NULL)
  1153. {
  1154. // Original data with Z
  1155. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1156. &parsingResult.year,
  1157. &parsingResult.month,
  1158. &parsingResult.mday,
  1159. &parsingResult.hour,
  1160. &parsingResult.min,
  1161. &parsingResult.sec);
  1162. }
  1163. else
  1164. {
  1165. // Original data without Z
  1166. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1167. &parsingResult.year,
  1168. &parsingResult.month,
  1169. &parsingResult.mday,
  1170. &parsingResult.hour,
  1171. &parsingResult.min,
  1172. &parsingResult.sec,
  1173. &parsingResult.tz_hour,
  1174. &parsingResult.tz_min);
  1175. }
  1176. }
  1177. if(parsingResult.scanedElement >= 6)
  1178. {
  1179. tmStart.tm_year = parsingResult.year - 1900;
  1180. tmStart.tm_mon = parsingResult.month - 1;
  1181. tmStart.tm_mday = parsingResult.mday;
  1182. tmStart.tm_hour = parsingResult.hour;
  1183. tmStart.tm_min = parsingResult.min;
  1184. tmStart.tm_sec = parsingResult.sec;
  1185. tmStart.tm_gmtoff = 0;
  1186. tbStart.time = mktime(&tmStart);
  1187. tbStart.timezone = 0;
  1188. tbStart.millitm = 0;
  1189. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1190. if(DiffTimebWithNowSec(tbStart) <= 0)
  1191. result = NO;
  1192. else
  1193. result = YES;
  1194. }
  1195. else
  1196. {
  1197. DEBUG_WARN("Start date parsing error.\n");
  1198. }
  1199. return result;
  1200. }
  1201. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. };
  1217. struct ParsingResult parseStart;
  1218. struct ParsingResult parseStop;
  1219. int result = -1;
  1220. struct tm tmStart;
  1221. struct timeb tbStart;
  1222. struct tm tmStop;
  1223. struct timeb tbStop;
  1224. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1225. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1226. // Scan start & stop date time
  1227. if(strstr((char*)start, ".") != NULL)
  1228. {
  1229. // Original data with mini second
  1230. if(strstr((char*)start, "Z") != NULL)
  1231. {
  1232. // Original data with Z
  1233. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1234. &parseStart.year,
  1235. &parseStart.month,
  1236. &parseStart.mday,
  1237. &parseStart.hour,
  1238. &parseStart.min,
  1239. &parseStart.sec,
  1240. &parseStart.minSec);
  1241. }
  1242. else
  1243. {
  1244. // Original data without Z
  1245. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1246. &parseStart.year,
  1247. &parseStart.month,
  1248. &parseStart.mday,
  1249. &parseStart.hour,
  1250. &parseStart.min,
  1251. &parseStart.sec,
  1252. &parseStart.minSec,
  1253. &parseStart.tz_hour,
  1254. &parseStart.tz_min);
  1255. }
  1256. }
  1257. else
  1258. {
  1259. // Original data without mini second
  1260. if(strstr((char*)start, "Z") != NULL)
  1261. {
  1262. // Original data with Z
  1263. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1264. &parseStart.year,
  1265. &parseStart.month,
  1266. &parseStart.mday,
  1267. &parseStart.hour,
  1268. &parseStart.min,
  1269. &parseStart.sec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1275. &parseStart.year,
  1276. &parseStart.month,
  1277. &parseStart.mday,
  1278. &parseStart.hour,
  1279. &parseStart.min,
  1280. &parseStart.sec,
  1281. &parseStart.tz_hour,
  1282. &parseStart.tz_min);
  1283. }
  1284. }
  1285. if(strstr((char*)stop, ".") != NULL)
  1286. {
  1287. // Original data with mini second
  1288. if(strstr((char*)stop, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1292. &parseStop.year,
  1293. &parseStop.month,
  1294. &parseStop.mday,
  1295. &parseStop.hour,
  1296. &parseStop.min,
  1297. &parseStop.sec,
  1298. &parseStop.minSec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1304. &parseStop.year,
  1305. &parseStop.month,
  1306. &parseStop.mday,
  1307. &parseStop.hour,
  1308. &parseStop.min,
  1309. &parseStop.sec,
  1310. &parseStop.minSec,
  1311. &parseStop.tz_hour,
  1312. &parseStop.tz_min);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. // Original data without mini second
  1318. if(strstr((char*)stop, "Z") != NULL)
  1319. {
  1320. // Original data with Z
  1321. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1322. &parseStop.year,
  1323. &parseStop.month,
  1324. &parseStop.mday,
  1325. &parseStop.hour,
  1326. &parseStop.min,
  1327. &parseStop.sec);
  1328. }
  1329. else
  1330. {
  1331. // Original data without Z
  1332. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1333. &parseStop.year,
  1334. &parseStop.month,
  1335. &parseStop.mday,
  1336. &parseStop.hour,
  1337. &parseStop.min,
  1338. &parseStop.sec,
  1339. &parseStop.tz_hour,
  1340. &parseStop.tz_min);
  1341. }
  1342. }
  1343. // Calculate date time difference
  1344. if((parseStart.scanedElement >=6) &&
  1345. (parseStop.scanedElement >=6))
  1346. {
  1347. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1348. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1349. tmStart.tm_year = parseStart.year - 1900;
  1350. tmStart.tm_mon = parseStart.month - 1;
  1351. tmStart.tm_mday = parseStart.mday;
  1352. tmStart.tm_hour = parseStart.hour;
  1353. tmStart.tm_min = parseStart.min;
  1354. tmStart.tm_sec = parseStart.sec;
  1355. tmStart.tm_gmtoff = 0;
  1356. tbStart.time = mktime(&tmStart);
  1357. tbStart.timezone = 0;
  1358. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1359. tmStop.tm_year = parseStop.year - 1900;
  1360. tmStop.tm_mon = parseStop.month - 1;
  1361. tmStop.tm_mday = parseStop.mday;
  1362. tmStop.tm_hour = parseStop.hour;
  1363. tmStop.tm_min = parseStop.min;
  1364. tmStop.tm_sec = parseStop.sec;
  1365. tmStop.tm_gmtoff = 0;
  1366. tbStop.time = mktime(&tmStop);
  1367. tbStop.timezone = 0;
  1368. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1369. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1379. {
  1380. FILE *fp;
  1381. char profileFileName[128];
  1382. char *line = NULL;
  1383. size_t len = 0;
  1384. time_t CurrentTime;
  1385. struct tm *tmComposite;
  1386. struct StructChargingProfile maxProfile;
  1387. struct StructChargingProfile compositeProfile;
  1388. uint8_t limitMax=0;
  1389. int compositePeriodIdx = 0;
  1390. CurrentTime = time(NULL);
  1391. tmComposite=localtime(&CurrentTime);
  1392. 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);
  1393. if(isUnitA)
  1394. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1395. else
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1397. compositeProfile.ChargingSchedule.Duration = durationReq;
  1398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1399. {
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1403. }
  1404. compositeProfile.ChargingProfileId = 0;
  1405. compositeProfile.StackLevel = 99 ;
  1406. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1407. maxProfile.ChargingProfileId = -1;
  1408. maxProfile.ChargingSchedule.Duration = -1;
  1409. system("rm -f /tmp/*.json");
  1410. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1411. // Search max profile
  1412. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. while(getline(&line, &len, fp) != -1)
  1417. {
  1418. json_object *obj = NULL;
  1419. obj = json_tokener_parse(line);
  1420. if(is_error(obj))
  1421. {
  1422. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1423. }
  1424. else
  1425. {
  1426. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1427. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1428. )
  1429. {
  1430. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1431. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1432. )
  1433. {
  1434. struct tm tmFrom, tmTo;
  1435. struct timeb tbFrom, tbTo;
  1436. 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) &&
  1437. (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))
  1438. {
  1439. tmFrom.tm_year -= 1900;
  1440. tmFrom.tm_mon -= 1;
  1441. tbFrom.time = mktime(&tmFrom);
  1442. tmTo.tm_year -= 1900;
  1443. tmTo.tm_mon -= 1;
  1444. tbTo.time = mktime(&tmTo);
  1445. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1446. {
  1447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1448. {
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1452. }
  1453. if(maxProfile.ChargingProfileId == -1)
  1454. DEBUG_INFO("MaxProfile found.\n");
  1455. else
  1456. DEBUG_INFO("MaxProfile updated.\n");
  1457. // Required item
  1458. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1459. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1460. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1461. if(isUnitA)
  1462. {
  1463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1464. 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++)
  1465. {
  1466. 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"));
  1467. 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?
  1468. 3:
  1469. 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")));
  1470. 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")));
  1471. }
  1472. }
  1473. else
  1474. {
  1475. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1476. 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++)
  1477. {
  1478. 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"));
  1479. 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?
  1480. 3:
  1481. 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")));
  1482. 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));
  1483. }
  1484. }
  1485. // Optional item
  1486. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1487. {
  1488. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1489. }
  1490. else
  1491. {
  1492. sprintf((char*)maxProfile.ValidFrom, " ");
  1493. }
  1494. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1495. {
  1496. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1497. }
  1498. else
  1499. {
  1500. sprintf((char*)maxProfile.ValidTo, " ");
  1501. }
  1502. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1503. {
  1504. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1505. }
  1506. else
  1507. {
  1508. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1509. }
  1510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1511. {
  1512. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1513. }
  1514. else
  1515. {
  1516. maxProfile.TransactionId = -1;
  1517. }
  1518. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1519. {
  1520. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1521. }
  1522. else
  1523. {
  1524. maxProfile.ChargingSchedule.Duration = 86400;
  1525. }
  1526. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1527. {
  1528. 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")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1535. {
  1536. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1537. }
  1538. else
  1539. {
  1540. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. if(maxProfile.ChargingProfileId == -1)
  1554. DEBUG_INFO("MaxProfile found.\n");
  1555. else
  1556. DEBUG_INFO("MaxProfile updated.\n");
  1557. // Required item
  1558. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1559. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1560. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1561. if(isUnitA)
  1562. {
  1563. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1564. 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++)
  1565. {
  1566. 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"));
  1567. 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?
  1568. 3:
  1569. 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")));
  1570. 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")));
  1571. }
  1572. }
  1573. else
  1574. {
  1575. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1576. 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++)
  1577. {
  1578. 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"));
  1579. 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?
  1580. 3:
  1581. 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")));
  1582. 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));
  1583. }
  1584. }
  1585. // Optional item
  1586. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ValidFrom, " ");
  1593. }
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidTo, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1611. {
  1612. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1613. }
  1614. else
  1615. {
  1616. maxProfile.TransactionId = -1;
  1617. }
  1618. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.ChargingSchedule.Duration = 86400;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1627. {
  1628. 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")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1637. }
  1638. else
  1639. {
  1640. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. json_object_put(obj);
  1646. }
  1647. fclose(fp);
  1648. /*
  1649. if(maxProfile.ChargingProfileId !=-1)
  1650. {
  1651. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1652. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1653. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1654. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1655. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1656. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1657. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1658. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1659. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1660. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1661. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1665. {
  1666. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1667. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1668. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1669. }
  1670. }
  1671. }
  1672. else
  1673. DEBUG_INFO("MaxProfile not found.\n");
  1674. DEBUG_INFO("------------------------------------\n");*/
  1675. }
  1676. if(maxProfile.ChargingProfileId != -1)
  1677. {
  1678. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1679. {
  1680. if(maxProfile.ChargingSchedule.Duration != -1)
  1681. {
  1682. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1683. 0:
  1684. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1685. }
  1686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1687. {
  1688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. if(idxPeriod > 0)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1704. {
  1705. if(maxProfile.ChargingSchedule.Duration != -1)
  1706. {
  1707. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1708. }
  1709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1710. {
  1711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1712. {
  1713. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1714. if(idxPeriod > 0)
  1715. {
  1716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1717. {
  1718. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. else
  1725. {
  1726. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1727. {
  1728. if(maxProfile.ChargingSchedule.Duration != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1733. }
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. if(idxPeriod > 0)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(maxProfile.ChargingSchedule.Duration != -1)
  1754. {
  1755. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1756. 0:
  1757. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1758. }
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1762. {
  1763. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. if(idxPeriod > 0)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. DEBUG_INFO("MaxProfile after align.\n");
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. DEBUG_INFO("------------------------------------\n");*/
  1800. }
  1801. // Find each profile period quantity
  1802. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1803. {
  1804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1805. limitMax = idx+1;
  1806. }
  1807. if(maxProfile.ChargingProfileId != -1)
  1808. {
  1809. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1810. {
  1811. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1812. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1813. (maxProfile.ChargingSchedule.Duration > 0))
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1816. {
  1817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1818. compositePeriodIdx++;
  1819. }
  1820. else
  1821. {
  1822. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. }
  1824. }
  1825. }
  1826. }
  1827. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1828. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1829. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1830. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. compositeProfile.ChargingProfileId = 1;
  1836. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1837. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1838. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1839. }
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1841. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1844. }
  1845. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1846. if(line)
  1847. free(line);
  1848. }
  1849. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1850. {
  1851. FILE *fp;
  1852. char profileFileName[128];
  1853. char *line = NULL;
  1854. size_t len = 0;
  1855. time_t CurrentTime;
  1856. struct tm *tmComposite;
  1857. struct StructChargingProfile maxProfile;
  1858. struct StructChargingProfile defaultTxProfile;
  1859. struct StructChargingProfile txProfile;
  1860. struct StructChargingProfile compositeProfile;
  1861. struct StructChargingSchedulePeriod tmpPeriod;
  1862. uint8_t limitMax=0;
  1863. uint8_t limitDef=0;
  1864. uint8_t limitTx=0;
  1865. int compositePeriodIdx = 0;
  1866. CurrentTime = time(NULL);
  1867. tmComposite=localtime(&CurrentTime);
  1868. 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);
  1869. if(isUnitA)
  1870. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1871. else
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1873. compositeProfile.ChargingSchedule.Duration = durationReq;
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. compositeProfile.ChargingProfileId = 0;
  1881. compositeProfile.StackLevel = 99 ;
  1882. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1883. maxProfile.ChargingProfileId = -1;
  1884. defaultTxProfile.ChargingProfileId = -1;
  1885. txProfile.ChargingProfileId = -1;
  1886. maxProfile.ChargingSchedule.Duration = -1;
  1887. defaultTxProfile.ChargingSchedule.Duration = -1;
  1888. txProfile.ChargingSchedule.Duration = -1;
  1889. system("rm -f /tmp/*.json");
  1890. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1891. /*
  1892. * Search valid charging profile
  1893. */
  1894. //DEBUG_INFO("====================================\n");
  1895. // Search tx profile
  1896. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1897. if((access(profileFileName, F_OK))!=-1)
  1898. {
  1899. fp = fopen(profileFileName, "r");
  1900. while(getline(&line, &len, fp) != -1)
  1901. {
  1902. json_object *obj = NULL;
  1903. obj = json_tokener_parse(line);
  1904. if(is_error(obj))
  1905. {
  1906. DEBUG_ERROR("Parse txProfile from file error.\n");
  1907. }
  1908. else
  1909. {
  1910. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1911. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1912. )
  1913. {
  1914. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1915. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1916. )
  1917. {
  1918. struct tm tmFrom, tmTo;
  1919. struct timeb tbFrom, tbTo;
  1920. 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) &&
  1921. (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))
  1922. {
  1923. tmFrom.tm_year -= 1900;
  1924. tmFrom.tm_mon -= 1;
  1925. tbFrom.time = mktime(&tmFrom);
  1926. tmTo.tm_year -= 1900;
  1927. tmTo.tm_mon -= 1;
  1928. tbTo.time = mktime(&tmTo);
  1929. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1930. {
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1936. }
  1937. if(txProfile.ChargingProfileId == -1)
  1938. DEBUG_INFO("TxProfile found.\n");
  1939. else
  1940. DEBUG_INFO("TxProfile updated.\n");
  1941. // Required item
  1942. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1943. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1944. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1945. if(isUnitA)
  1946. {
  1947. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1948. 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++)
  1949. {
  1950. 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"));
  1951. 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?
  1952. 3:
  1953. 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")));
  1954. 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")));
  1955. }
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1960. 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++)
  1961. {
  1962. 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"));
  1963. 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?
  1964. 3:
  1965. 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")));
  1966. 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));
  1967. }
  1968. }
  1969. // Optional item
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1971. {
  1972. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)txProfile.ValidFrom, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidTo, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.RecurrencyKind, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1995. {
  1996. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1997. }
  1998. else
  1999. {
  2000. txProfile.TransactionId = -1;
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2003. {
  2004. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.ChargingSchedule.Duration = 86400;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2011. {
  2012. 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")));
  2013. }
  2014. else
  2015. {
  2016. 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));
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2019. {
  2020. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2021. }
  2022. else
  2023. {
  2024. txProfile.ChargingSchedule.MinChargingRate = -1;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. else
  2030. {
  2031. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2032. {
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2036. }
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. 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++)
  2049. {
  2050. 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"));
  2051. 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?
  2052. 3:
  2053. 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")));
  2054. 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")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. 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")));
  2113. }
  2114. else
  2115. {
  2116. 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));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. json_object_put(obj);
  2130. }
  2131. fclose(fp);
  2132. /*
  2133. if(txProfile.ChargingProfileId != -1)
  2134. {
  2135. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2136. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2137. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2138. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2139. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2140. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2141. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2142. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2143. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2144. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2145. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2147. {
  2148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2149. {
  2150. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2151. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2152. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2153. }
  2154. }
  2155. }
  2156. else
  2157. DEBUG_INFO("TxProfile not found.\n");*/
  2158. }
  2159. // Search default tx profile
  2160. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2161. if((access(profileFileName, F_OK))==-1)
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2163. if((access(profileFileName, F_OK))!=-1)
  2164. {
  2165. fp = fopen(profileFileName, "r");
  2166. while(getline(&line, &len, fp) != -1)
  2167. {
  2168. json_object *obj = NULL;
  2169. obj = json_tokener_parse(line);
  2170. if(is_error(obj))
  2171. {
  2172. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2173. }
  2174. else
  2175. {
  2176. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2177. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2178. )
  2179. {
  2180. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2181. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2182. )
  2183. {
  2184. struct tm tmFrom, tmTo;
  2185. struct timeb tbFrom, tbTo;
  2186. 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) &&
  2187. (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))
  2188. {
  2189. tmFrom.tm_year -= 1900;
  2190. tmFrom.tm_mon -= 1;
  2191. tbFrom.time = mktime(&tmFrom);
  2192. tmTo.tm_year -= 1900;
  2193. tmTo.tm_mon -= 1;
  2194. tbTo.time = mktime(&tmTo);
  2195. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2196. {
  2197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2198. {
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2202. }
  2203. if(defaultTxProfile.ChargingProfileId == -1)
  2204. DEBUG_INFO("TxDefaultProfile found.\n");
  2205. else
  2206. DEBUG_INFO("TxDefaultProfile updated.\n");
  2207. // Required item
  2208. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2209. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2210. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2211. if(isUnitA)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2214. 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++)
  2215. {
  2216. 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"));
  2217. 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?
  2218. 3:
  2219. 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")));
  2220. 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")));
  2221. }
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2226. 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++)
  2227. {
  2228. 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"));
  2229. 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?
  2230. 3:
  2231. 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")));
  2232. 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));
  2233. }
  2234. }
  2235. // Optional item
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2237. {
  2238. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2239. }
  2240. else
  2241. {
  2242. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2243. }
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2261. {
  2262. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2263. }
  2264. else
  2265. {
  2266. defaultTxProfile.TransactionId = -1;
  2267. }
  2268. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2269. {
  2270. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2277. {
  2278. 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")));
  2279. }
  2280. else
  2281. {
  2282. 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));
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2285. {
  2286. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2287. }
  2288. else
  2289. {
  2290. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. if(defaultTxProfile.ChargingProfileId == -1)
  2304. DEBUG_INFO("TxDefaultProfile found.\n");
  2305. else
  2306. DEBUG_INFO("TxDefaultProfile updated.\n");
  2307. // Required item
  2308. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2309. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2310. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2311. if(isUnitA)
  2312. {
  2313. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2314. 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++)
  2315. {
  2316. 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"));
  2317. 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?
  2318. 3:
  2319. 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")));
  2320. 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")));
  2321. }
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2326. 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++)
  2327. {
  2328. 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"));
  2329. 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?
  2330. 3:
  2331. 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")));
  2332. 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));
  2333. }
  2334. }
  2335. // Optional item
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2337. {
  2338. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2361. {
  2362. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2363. }
  2364. else
  2365. {
  2366. defaultTxProfile.TransactionId = -1;
  2367. }
  2368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2369. {
  2370. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2377. {
  2378. 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")));
  2379. }
  2380. else
  2381. {
  2382. 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));
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2385. {
  2386. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2387. }
  2388. else
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. json_object_put(obj);
  2396. }
  2397. fclose(fp);
  2398. /*
  2399. if(defaultTxProfile.ChargingProfileId != -1)
  2400. {
  2401. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2402. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2403. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2404. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2405. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2406. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2407. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2408. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2409. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2410. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2411. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2413. {
  2414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2415. {
  2416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2419. }
  2420. }
  2421. }
  2422. else
  2423. DEBUG_INFO("TxDefaultProfile not found.\n");
  2424. DEBUG_INFO("------------------------------------\n");*/
  2425. }
  2426. // Search max profile
  2427. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2428. if((access(profileFileName, F_OK))!=-1)
  2429. {
  2430. fp = fopen(profileFileName, "r");
  2431. while(getline(&line, &len, fp) != -1)
  2432. {
  2433. json_object *obj = NULL;
  2434. obj = json_tokener_parse(line);
  2435. if(is_error(obj))
  2436. {
  2437. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2438. }
  2439. else
  2440. {
  2441. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2442. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2443. )
  2444. {
  2445. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2446. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2447. )
  2448. {
  2449. struct tm tmFrom, tmTo;
  2450. struct timeb tbFrom, tbTo;
  2451. 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) &&
  2452. (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))
  2453. {
  2454. tmFrom.tm_year -= 1900;
  2455. tmFrom.tm_mon -= 1;
  2456. tbFrom.time = mktime(&tmFrom);
  2457. tmTo.tm_year -= 1900;
  2458. tmTo.tm_mon -= 1;
  2459. tbTo.time = mktime(&tmTo);
  2460. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2461. {
  2462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2467. }
  2468. if(maxProfile.ChargingProfileId == -1)
  2469. DEBUG_INFO("MaxProfile found.\n");
  2470. else
  2471. DEBUG_INFO("MaxProfile updated.\n");
  2472. // Required item
  2473. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2474. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2475. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2476. if(isUnitA)
  2477. {
  2478. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2479. 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++)
  2480. {
  2481. 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"));
  2482. 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?
  2483. 3:
  2484. 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")));
  2485. 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")));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2491. 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++)
  2492. {
  2493. 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"));
  2494. 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?
  2495. 3:
  2496. 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")));
  2497. 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));
  2498. }
  2499. }
  2500. // Optional item
  2501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2502. {
  2503. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2504. }
  2505. else
  2506. {
  2507. sprintf((char*)maxProfile.ValidFrom, " ");
  2508. }
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidTo, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2526. {
  2527. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2528. }
  2529. else
  2530. {
  2531. maxProfile.TransactionId = -1;
  2532. }
  2533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2534. {
  2535. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.ChargingSchedule.Duration = 86400;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2542. {
  2543. 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")));
  2544. }
  2545. else
  2546. {
  2547. 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));
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2550. {
  2551. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2552. }
  2553. else
  2554. {
  2555. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2567. }
  2568. if(maxProfile.ChargingProfileId == -1)
  2569. DEBUG_INFO("MaxProfile found.\n");
  2570. else
  2571. DEBUG_INFO("MaxProfile updated.\n");
  2572. // Required item
  2573. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2574. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2575. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2576. if(isUnitA)
  2577. {
  2578. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2579. 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++)
  2580. {
  2581. 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"));
  2582. 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?
  2583. 3:
  2584. 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")));
  2585. 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")));
  2586. }
  2587. }
  2588. else
  2589. {
  2590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2591. 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++)
  2592. {
  2593. 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"));
  2594. 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?
  2595. 3:
  2596. 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")));
  2597. 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));
  2598. }
  2599. }
  2600. // Optional item
  2601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2602. {
  2603. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2604. }
  2605. else
  2606. {
  2607. sprintf((char*)maxProfile.ValidFrom, " ");
  2608. }
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidTo, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2626. {
  2627. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2628. }
  2629. else
  2630. {
  2631. maxProfile.TransactionId = -1;
  2632. }
  2633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2634. {
  2635. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.ChargingSchedule.Duration = 86400;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2642. {
  2643. 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")));
  2644. }
  2645. else
  2646. {
  2647. 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));
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2650. {
  2651. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2652. }
  2653. else
  2654. {
  2655. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. json_object_put(obj);
  2661. }
  2662. fclose(fp);
  2663. /*
  2664. if(maxProfile.ChargingProfileId !=-1)
  2665. {
  2666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2672. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2673. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2680. {
  2681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. DEBUG_INFO("MaxProfile not found.\n");
  2689. DEBUG_INFO("------------------------------------\n");*/
  2690. }
  2691. /*
  2692. * Align found profile start schedule & periods
  2693. */
  2694. //DEBUG_INFO("====================================\n");
  2695. /*
  2696. // For local test usage, force modify found profile start schedule info
  2697. 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);
  2698. 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);
  2699. 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);
  2700. */
  2701. if(txProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(txProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2729. {
  2730. if(txProfile.ChargingSchedule.Duration != -1)
  2731. {
  2732. 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?
  2733. 0:
  2734. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2735. }
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2739. {
  2740. 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?
  2741. 0:
  2742. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. if(idxPeriod > 0)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2756. {
  2757. if(txProfile.ChargingSchedule.Duration != -1)
  2758. {
  2759. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2762. }
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2766. {
  2767. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. if(idxPeriod > 0)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. else
  2781. {
  2782. if(txProfile.ChargingSchedule.Duration != -1)
  2783. {
  2784. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2785. 0:
  2786. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2787. }
  2788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2789. {
  2790. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2791. {
  2792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. if(idxPeriod > 0)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. /*
  2807. DEBUG_INFO("txProfile after align.\n");
  2808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2815. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2822. {
  2823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2826. }
  2827. }*/
  2828. }
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2832. {
  2833. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2836. 0:
  2837. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2859. {
  2860. 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?
  2861. 0:
  2862. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2863. }
  2864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2867. {
  2868. 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?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. if(idxPeriod > 0)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2890. }
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. if(idxPeriod > 0)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2911. {
  2912. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2913. 0:
  2914. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2915. }
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /*
  2935. DEBUG_INFO("defaultTxProfile after align.\n");
  2936. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2937. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2938. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2939. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2940. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2941. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2942. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2943. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2944. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2945. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2946. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2950. {
  2951. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2952. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2953. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2954. }
  2955. }
  2956. DEBUG_INFO("------------------------------------\n");*/
  2957. }
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2961. {
  2962. if(maxProfile.ChargingSchedule.Duration != -1)
  2963. {
  2964. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2965. 0:
  2966. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2967. }
  2968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2969. {
  2970. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. if(idxPeriod > 0)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2986. {
  2987. if(maxProfile.ChargingSchedule.Duration != -1)
  2988. {
  2989. 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?
  2990. 0:
  2991. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2992. }
  2993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2994. {
  2995. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2996. {
  2997. 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?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. if(idxPeriod > 0)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3013. {
  3014. if(maxProfile.ChargingSchedule.Duration != -1)
  3015. {
  3016. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. }
  3020. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3021. {
  3022. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. if(idxPeriod > 0)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. else
  3038. {
  3039. if(maxProfile.ChargingSchedule.Duration != -1)
  3040. {
  3041. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3044. }
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("MaxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. /*
  3088. * Merge to conposite schedule
  3089. */
  3090. //DEBUG_INFO("====================================\n");
  3091. // Find each profile period quantity
  3092. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3095. limitMax = idx+1;
  3096. }
  3097. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3098. {
  3099. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3100. limitDef = idx+1;
  3101. }
  3102. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3103. {
  3104. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3105. limitTx = idx+1;
  3106. }
  3107. // TxProfile found, composite schedule based on it
  3108. if(txProfile.ChargingProfileId != -1)
  3109. {
  3110. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3111. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3112. {
  3113. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3114. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3115. (txProfile.ChargingSchedule.Duration > 0))
  3116. {
  3117. if(maxProfile.ChargingProfileId != -1)
  3118. {
  3119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3122. {
  3123. if((maxProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3126. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3127. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3128. }
  3129. else
  3130. {
  3131. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3132. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3133. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3134. }
  3135. }
  3136. if(idxMaxPeriod == (limitMax-1))
  3137. {
  3138. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3139. {
  3140. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3141. {
  3142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3143. compositePeriodIdx++;
  3144. }
  3145. else
  3146. {
  3147. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3156. {
  3157. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3158. compositePeriodIdx++;
  3159. }
  3160. else
  3161. {
  3162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3163. }
  3164. }
  3165. }
  3166. if(idxTxPeriod == (limitTx-1))
  3167. {
  3168. if(defaultTxProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3171. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3172. {
  3173. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3174. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3175. (defaultTxProfile.ChargingSchedule.Duration>0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  3190. {
  3191. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3193. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3194. }
  3195. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3196. {
  3197. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. // Delete duplicate period
  3208. if(compositePeriodIdx > 1)
  3209. {
  3210. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3211. {
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3213. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3214. compositePeriodIdx -= 1;
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. break;
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3236. {
  3237. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. compositePeriodIdx++;
  3239. }
  3240. else
  3241. {
  3242. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3252. else if(defaultTxProfile.ChargingProfileId != -1)
  3253. {
  3254. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3255. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3256. {
  3257. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3258. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3259. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3260. {
  3261. if(maxProfile.ChargingProfileId != -1)
  3262. {
  3263. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3264. {
  3265. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3266. {
  3267. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3268. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3269. if((maxProfile.ChargingSchedule.Duration > 0))
  3270. {
  3271. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3272. }
  3273. else
  3274. {
  3275. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3276. }
  3277. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3278. {
  3279. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. // Delete duplicate period
  3290. if(compositePeriodIdx > 1)
  3291. {
  3292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3293. {
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3295. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3296. compositePeriodIdx -= 1;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. else
  3316. {
  3317. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. compositePeriodIdx++;
  3321. }
  3322. else
  3323. {
  3324. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. // Fill other period by MaxProfile
  3331. if(maxProfile.ChargingProfileId != -1)
  3332. {
  3333. if(compositePeriodIdx==0)
  3334. {
  3335. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3337. {
  3338. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3339. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3340. (maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3343. {
  3344. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3345. compositePeriodIdx++;
  3346. }
  3347. else
  3348. {
  3349. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else
  3355. {
  3356. int lastCompositePeriodIdx = compositePeriodIdx;
  3357. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3358. {
  3359. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3360. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3361. (maxProfile.ChargingSchedule.Duration > 0))
  3362. {
  3363. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3364. {
  3365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3366. {
  3367. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3368. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3369. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3370. }
  3371. else
  3372. {
  3373. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3374. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3376. }
  3377. }
  3378. if(tmpPeriod.Limit != -1)
  3379. {
  3380. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3381. {
  3382. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. // Delete duplicate period
  3393. if(compositePeriodIdx > 1)
  3394. {
  3395. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3396. {
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3398. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3399. compositePeriodIdx -= 1;
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. compositeProfile.ChargingSchedule.Duration = durationReq;
  3408. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3409. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3413. {
  3414. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3415. {
  3416. compositeProfile.ChargingProfileId = 1;
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3422. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3425. }
  3426. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3427. if(line)
  3428. free(line);
  3429. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3430. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3431. }
  3432. //==========================================
  3433. // Init all share memory
  3434. //==========================================
  3435. int InitShareMemory()
  3436. {
  3437. int result = PASS;
  3438. int MeterSMId;
  3439. //creat ShmSysConfigAndInfo
  3440. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3441. {
  3442. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3443. result = FAIL;
  3444. }
  3445. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3446. {
  3447. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3448. result = FAIL;
  3449. }
  3450. else
  3451. {}
  3452. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3453. {
  3454. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3455. result = FAIL;
  3456. }
  3457. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3458. {
  3459. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3460. result = FAIL;
  3461. }
  3462. else
  3463. {}
  3464. //creat ShmPsuData
  3465. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3466. {
  3467. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3471. {
  3472. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3473. result = FAIL;
  3474. }
  3475. else
  3476. {}
  3477. //link ShmOCPP16Data
  3478. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3479. {
  3480. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3481. result = FAIL;
  3482. }
  3483. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3484. {
  3485. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3486. result = FAIL;
  3487. }
  3488. else
  3489. {}
  3490. //creat ShmOCPP16DataPH
  3491. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3492. {
  3493. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3494. result = FAIL;
  3495. }
  3496. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3497. {
  3498. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3499. result = FAIL;
  3500. }
  3501. else
  3502. {}
  3503. /****************************** For Initial Settings************************************************/
  3504. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3505. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3506. // allocate Configuration memory address
  3507. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3509. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3510. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3511. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3512. //offline MeterValue Interval
  3513. TempMeterValueInterval = 0;
  3514. return result;
  3515. }
  3516. int ProcessShareMemory()
  3517. {
  3518. int result = PASS;
  3519. if(InitShareMemory() == FAIL)
  3520. {
  3521. DEBUG_ERROR("InitShareMemory NG\n");
  3522. if(ShmStatusCodeData!=NULL)
  3523. {
  3524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3525. }
  3526. result = FAIL;
  3527. }
  3528. // Model name parsing
  3529. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3530. {
  3531. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3532. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3533. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3535. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3536. ) // 'D' means DC
  3537. {
  3538. // DO series
  3539. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3540. {
  3541. gunTotalNumber += 1;
  3542. gunType[gun_index] = GUN_TYPE_DO;
  3543. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3544. {
  3545. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3546. {
  3547. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3548. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3549. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3550. }
  3551. }
  3552. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3553. {
  3554. case Gun_Type_Chademo:
  3555. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3556. break;
  3557. case Gun_Type_CCS_2:
  3558. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3559. break;
  3560. case Gun_Type_GB:
  3561. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3562. break;
  3563. case Gun_Type_AC:
  3564. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3565. break;
  3566. default:
  3567. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3568. break;
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3575. {
  3576. gunTotalNumber += 1;
  3577. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3578. {
  3579. case Gun_Type_Chademo:
  3580. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3581. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3582. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3583. {
  3584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3585. {
  3586. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3587. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3588. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3589. }
  3590. }
  3591. break;
  3592. case Gun_Type_CCS_2:
  3593. gunType[gun_index] = GUN_TYPE_CCS;
  3594. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3595. for (int index = 0; index < CCS_QUANTITY; index++)
  3596. {
  3597. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3598. {
  3599. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3600. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3601. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3602. }
  3603. }
  3604. break;
  3605. case Gun_Type_GB:
  3606. gunType[gun_index] = GUN_TYPE_GBT;
  3607. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3608. for (int index = 0; index < GB_QUANTITY; index++)
  3609. {
  3610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3611. {
  3612. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3613. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3614. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3615. }
  3616. }
  3617. break;
  3618. case Gun_Type_AC:
  3619. gunType[gun_index] = GUN_TYPE_AC;
  3620. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3621. for (int index = 0; index < AC_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3624. {
  3625. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3626. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3627. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3628. }
  3629. }
  3630. break;
  3631. default:
  3632. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3633. break;
  3634. }
  3635. }
  3636. }
  3637. }
  3638. else
  3639. {
  3640. DEBUG_ERROR("Model name parsing fail.\n");
  3641. result = FAIL;
  3642. }
  3643. if(result != PASS)sleep(5);
  3644. return result;
  3645. }
  3646. void checkRemoteStart(uint8_t connectorIdInt)
  3647. {
  3648. uint8_t tempIndex;
  3649. int result = PASS;
  3650. char cmdBuf[512];
  3651. //check Transaction active
  3652. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3653. {
  3654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3655. {
  3656. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3657. }
  3658. else
  3659. {
  3660. tempIndex = connectorIdInt -1;
  3661. }
  3662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3663. {
  3664. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3665. {
  3666. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3667. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3668. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3669. {
  3670. //Reserved
  3671. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3672. }
  3673. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3675. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3676. {
  3677. //Reserved
  3678. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3679. result = FAIL;
  3680. goto end;
  3681. }
  3682. else
  3683. {
  3684. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3685. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3686. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3687. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3688. {
  3689. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3690. result = FAIL;
  3691. goto end;
  3692. }
  3693. }//END FOR ELSE
  3694. }
  3695. }// END FOR CHAdeMO_QUANTITY
  3696. }
  3697. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3698. {
  3699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3700. {
  3701. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3702. }
  3703. else
  3704. {
  3705. tempIndex = connectorIdInt -1;
  3706. }
  3707. for (int index = 0; index < CCS_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3710. {
  3711. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3713. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3714. {
  3715. //Reserved
  3716. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3717. }
  3718. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3720. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3721. {
  3722. //Reserved
  3723. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3724. result = FAIL;
  3725. goto end;
  3726. }
  3727. else
  3728. {
  3729. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3730. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3731. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3733. {
  3734. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3735. result = FAIL;
  3736. goto end;
  3737. }
  3738. }// END FOR ELSE
  3739. }
  3740. }// END FOR CCS_QUANTITY
  3741. }
  3742. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3743. {
  3744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3745. {
  3746. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3747. }
  3748. else
  3749. {
  3750. tempIndex = connectorIdInt -1;
  3751. }
  3752. for (int index = 0; index < GB_QUANTITY; index++)
  3753. {
  3754. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3755. {
  3756. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3757. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3758. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3759. {
  3760. //Reserved
  3761. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3762. }
  3763. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3765. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3766. {
  3767. //Reserved
  3768. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3769. result = FAIL;
  3770. goto end;
  3771. }
  3772. else
  3773. {
  3774. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3775. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3776. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3778. {
  3779. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3780. result = FAIL;
  3781. goto end;
  3782. }
  3783. }// END FOR ELSE
  3784. }
  3785. } // END FOR GB_QUANTITY
  3786. }
  3787. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3788. {
  3789. tempIndex = connectorIdInt -1;
  3790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3793. {
  3794. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3795. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3796. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3797. {
  3798. //Reserved
  3799. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3800. }
  3801. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3802. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3803. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3804. {
  3805. //Reserved
  3806. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3807. result = FAIL;
  3808. goto end;
  3809. }
  3810. else
  3811. {
  3812. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3813. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3814. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3815. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3816. {
  3817. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3818. result = FAIL;
  3819. goto end;
  3820. }
  3821. }// END FOR ELSE
  3822. }
  3823. } // END FOR GB_QUANTITY
  3824. }
  3825. else
  3826. {
  3827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3828. {
  3829. tempIndex = 2;
  3830. }
  3831. else
  3832. {
  3833. tempIndex = connectorIdInt -1;
  3834. }
  3835. for (int index = 0; index < AC_QUANTITY; index++)
  3836. {
  3837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3838. {
  3839. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3840. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3841. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3842. {
  3843. //Reserved
  3844. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3845. }
  3846. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3847. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3848. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3849. {
  3850. //Reserved
  3851. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3852. result = FAIL;
  3853. goto end;
  3854. }
  3855. else
  3856. {
  3857. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3858. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3859. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3860. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3861. {
  3862. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3863. result = FAIL;
  3864. goto end;
  3865. }
  3866. }//END FOR ELSE
  3867. }
  3868. }// END FOR AC_QUANTITY
  3869. }
  3870. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3871. {
  3872. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3873. {
  3874. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3875. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3876. {
  3877. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3878. system(cmdBuf);
  3879. }
  3880. }
  3881. else
  3882. {
  3883. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3884. result = FAIL;
  3885. }
  3886. }
  3887. end:
  3888. if(result == PASS)
  3889. {
  3890. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3891. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3892. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3893. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3895. }
  3896. }
  3897. void CheckSystemValue(void)
  3898. {
  3899. char filenmae[100]={0};
  3900. char str[100]={0};
  3901. int tempIndex = 0;
  3902. //===============================
  3903. // send Heartbeat
  3904. //===============================
  3905. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3906. {
  3907. //parameter for test
  3908. sendHeartbeatRequest(0);
  3909. //==============================================
  3910. // Reset Waiting Time
  3911. //==============================================
  3912. HeartBeatWithNOResponse += 2;
  3913. }
  3914. //===============================
  3915. // Credit deduct report
  3916. //===============================
  3917. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3918. {
  3919. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3920. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3921. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3922. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3923. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3924. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3925. }
  3926. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3927. {
  3928. OCPP_query_deduct_info();
  3929. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3930. }
  3931. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3932. {
  3933. // ClockAlign MeterValue
  3934. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3935. {
  3936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3937. {
  3938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3939. {
  3940. tempIndex = ((gun_index==2) ? 1: 0);
  3941. }
  3942. else
  3943. {
  3944. tempIndex = gun_index;
  3945. }
  3946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3947. {
  3948. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3949. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3950. {
  3951. reqClockAlignMeter[gun_index] = 1;
  3952. }
  3953. }// End for CHAdeMO
  3954. }
  3955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3956. {
  3957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3958. {
  3959. tempIndex = ((gun_index==2) ? 1: 0);
  3960. }
  3961. else
  3962. {
  3963. tempIndex = gun_index;
  3964. }
  3965. for (int index = 0; index < CCS_QUANTITY; index++)
  3966. {
  3967. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3968. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3969. {
  3970. reqClockAlignMeter[gun_index] = 1;
  3971. }
  3972. } // End for CCS
  3973. }
  3974. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3975. {
  3976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3977. {
  3978. tempIndex = ((gun_index==2) ? 1: 0);
  3979. }
  3980. else
  3981. {
  3982. tempIndex = gun_index;
  3983. }
  3984. for (int index = 0; index < GB_QUANTITY; index++)
  3985. {
  3986. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3987. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3988. {
  3989. reqClockAlignMeter[gun_index] = 1;
  3990. }
  3991. }// End for GB
  3992. }
  3993. else if(gunType[gun_index] == GUN_TYPE_DO)
  3994. {
  3995. tempIndex = gun_index;
  3996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3997. {
  3998. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3999. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4000. {
  4001. reqClockAlignMeter[gun_index] = 1;
  4002. }
  4003. }
  4004. }
  4005. else
  4006. {
  4007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4008. {
  4009. tempIndex = 2;
  4010. }
  4011. else
  4012. {
  4013. tempIndex = gun_index;
  4014. }
  4015. for (int index = 0; index < AC_QUANTITY; index++)
  4016. {
  4017. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4018. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4019. {
  4020. reqClockAlignMeter[gun_index] = 1;
  4021. }
  4022. }//End for AC
  4023. }
  4024. }
  4025. }
  4026. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4027. {
  4028. //==========================================
  4029. // Check remote start without connector id
  4030. //==========================================
  4031. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4032. {
  4033. int connectorIdInt = -1;
  4034. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4035. {
  4036. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4037. {
  4038. connectorIdInt = (gun_index+1);
  4039. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4040. checkRemoteStart(connectorIdInt);
  4041. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4042. break;
  4043. }
  4044. }
  4045. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4046. {
  4047. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4048. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4049. }
  4050. }
  4051. //==========================================
  4052. // csu trigger DataTransferReq
  4053. //==========================================
  4054. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4055. {
  4056. sendDataTransferRequest(gun_index);
  4057. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4058. }
  4059. //===============================
  4060. // CSU Trigger Authorize Request
  4061. //===============================
  4062. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4063. {
  4064. sendAuthorizeRequest(0);
  4065. authorizeRetryTimes = authorizeRetryTimes + 1;
  4066. if(authorizeRetryTimes < 3)
  4067. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4068. }
  4069. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4070. {
  4071. authorizeRetryTimes = 0;
  4072. SetOcppConnStatus(FALSE);
  4073. server_sign = FALSE;
  4074. }
  4075. 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))
  4076. {
  4077. sendAuthorizeRequest(0);
  4078. }
  4079. //==============================================
  4080. // Charger start transaction
  4081. //==============================================
  4082. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4083. {
  4084. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4085. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4086. sendStartTransactionRequest(gun_index);
  4087. refreshStartTimer(&clientTime.StartTransaction);
  4088. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4089. //storeTempStopTransaction(gun_index);
  4090. }
  4091. //==============================================
  4092. // Charger stop transaction
  4093. //==============================================
  4094. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4095. {
  4096. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4097. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4098. sendStopTransactionRequest(gun_index);
  4099. refreshStartTimer(&clientTime.StopTransaction);
  4100. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4101. }
  4102. //==============================================
  4103. // Charger status report
  4104. //==============================================
  4105. //--- Check Mode Change ---//
  4106. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4107. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4108. {
  4109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4110. {
  4111. tempIndex = ((gun_index==2) ? 1: 0);
  4112. }
  4113. else
  4114. {
  4115. tempIndex = gun_index;
  4116. }
  4117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4118. {
  4119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4120. {
  4121. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4122. {
  4123. // Sent unplug message for California pricing logic
  4124. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4125. {
  4126. uint8_t ts[36];
  4127. getNowDatetime(ts);
  4128. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4129. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4130. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4131. sendUnplugByDataTransferRequest(gun_index);
  4132. interLock.isSentUnplug[gun_index] = 1;
  4133. }
  4134. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4135. {
  4136. interLock.isSentUnplug[gun_index] = 0;
  4137. }
  4138. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4139. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4140. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4142. {
  4143. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4144. if((access(filenmae,F_OK))!=-1)
  4145. {
  4146. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4147. sprintf(str,"rm -f %s",filenmae);
  4148. system(str);
  4149. }
  4150. }
  4151. }
  4152. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4153. #if 1 // for TempStopTransaction
  4154. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4155. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4156. {
  4157. checkTempStopTransaction(gun_index);
  4158. }
  4159. #endif
  4160. }
  4161. }
  4162. }
  4163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4164. {
  4165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4166. {
  4167. tempIndex = ((gun_index==2) ? 1: 0);
  4168. }
  4169. else
  4170. {
  4171. tempIndex = gun_index;
  4172. }
  4173. for (int index = 0; index < CCS_QUANTITY; index++)
  4174. {
  4175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4176. {
  4177. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4178. {
  4179. // Sent unplug message for California pricing logic
  4180. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4181. {
  4182. uint8_t ts[36];
  4183. getNowDatetime(ts);
  4184. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4185. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4187. sendUnplugByDataTransferRequest(gun_index);
  4188. interLock.isSentUnplug[gun_index] = 1;
  4189. }
  4190. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4191. {
  4192. interLock.isSentUnplug[gun_index] = 0;
  4193. }
  4194. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4195. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4196. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4197. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4198. {
  4199. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4200. if((access(filenmae,F_OK))!=-1)
  4201. {
  4202. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4203. sprintf(str,"rm -f %s",filenmae);
  4204. system(str);
  4205. }
  4206. }
  4207. }
  4208. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4209. #if 1 // for TempStopTransaction
  4210. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4211. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4212. {
  4213. checkTempStopTransaction(gun_index);
  4214. }
  4215. #endif
  4216. }
  4217. }
  4218. }
  4219. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4220. {
  4221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4222. {
  4223. tempIndex = ((gun_index==2) ? 1: 0);
  4224. }
  4225. else
  4226. {
  4227. tempIndex = gun_index;
  4228. }
  4229. for (int index = 0; index < GB_QUANTITY; index++)
  4230. {
  4231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4232. {
  4233. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4234. {
  4235. // Sent unplug message for California pricing logic
  4236. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4237. {
  4238. uint8_t ts[36];
  4239. getNowDatetime(ts);
  4240. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4241. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4242. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4243. sendUnplugByDataTransferRequest(gun_index);
  4244. interLock.isSentUnplug[gun_index] = 1;
  4245. }
  4246. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4247. {
  4248. interLock.isSentUnplug[gun_index] = 0;
  4249. }
  4250. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4251. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4252. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4253. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4254. {
  4255. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4256. if((access(filenmae,F_OK))!=-1)
  4257. {
  4258. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4259. sprintf(str,"rm -f %s",filenmae);
  4260. system(str);
  4261. }
  4262. }
  4263. }
  4264. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4265. #if 1 // for TempStopTransaction
  4266. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4267. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4268. {
  4269. checkTempStopTransaction(gun_index);
  4270. }
  4271. #endif
  4272. }
  4273. }
  4274. }
  4275. else if(gunType[gun_index] == GUN_TYPE_DO)
  4276. {
  4277. tempIndex = gun_index;
  4278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4279. {
  4280. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4281. {
  4282. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4283. {
  4284. // Sent unplug message for California pricing logic
  4285. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4286. {
  4287. uint8_t ts[36];
  4288. getNowDatetime(ts);
  4289. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4290. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4291. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4292. sendUnplugByDataTransferRequest(gun_index);
  4293. interLock.isSentUnplug[gun_index] = 1;
  4294. }
  4295. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4296. {
  4297. interLock.isSentUnplug[gun_index] = 0;
  4298. }
  4299. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4300. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4301. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4302. 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
  4303. {
  4304. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4305. if((access(filenmae,F_OK))!=-1)
  4306. {
  4307. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4308. sprintf(str,"rm -f %s",filenmae);
  4309. system(str);
  4310. }
  4311. }
  4312. }
  4313. 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);
  4314. #if 1 // for TempStopTransaction
  4315. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4316. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4317. {
  4318. checkTempStopTransaction(gun_index);
  4319. }
  4320. #endif
  4321. }
  4322. }
  4323. }
  4324. else
  4325. {
  4326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4327. {
  4328. tempIndex = 2;
  4329. }
  4330. else
  4331. {
  4332. tempIndex = gun_index;
  4333. }
  4334. for (int index = 0; index < AC_QUANTITY; index++)
  4335. {
  4336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4337. {
  4338. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4339. {
  4340. // Sent unplug message for California pricing logic
  4341. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4342. {
  4343. uint8_t ts[36];
  4344. getNowDatetime(ts);
  4345. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4346. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4347. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4348. sendUnplugByDataTransferRequest(gun_index);
  4349. interLock.isSentUnplug[gun_index] = 1;
  4350. }
  4351. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4352. {
  4353. interLock.isSentUnplug[gun_index] = 0;
  4354. }
  4355. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4356. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4357. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4359. {
  4360. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4361. if((access(filenmae,F_OK))!=-1)
  4362. {
  4363. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4364. sprintf(str,"rm -f %s",filenmae);
  4365. system(str);
  4366. }
  4367. }
  4368. }
  4369. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4370. #if 1 // for TempStopTransaction
  4371. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4372. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4373. {
  4374. checkTempStopTransaction(gun_index);
  4375. }
  4376. #endif
  4377. }
  4378. }// END
  4379. }
  4380. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4381. (
  4382. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4383. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4384. )
  4385. )
  4386. {
  4387. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4388. sendStatusNotificationRequest(gun_index);
  4389. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4390. }
  4391. //==============================================
  4392. // TCCI reader status report
  4393. //==============================================
  4394. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4395. {
  4396. reportReaderStatus(gun_index);
  4397. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4398. }
  4399. //==============================================
  4400. // CSU Trigger Smart Charging Profile
  4401. //==============================================
  4402. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4403. {
  4404. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4405. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4406. }
  4407. //==============================================
  4408. // Meter report
  4409. //==============================================
  4410. // Trigger MeterValue
  4411. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4412. {
  4413. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4414. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4415. }
  4416. // Clock-aligned Meter value
  4417. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4418. {
  4419. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4420. reqClockAlignMeter[gun_index] = 0;
  4421. }
  4422. // Sample period MeterValue
  4423. 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))))
  4424. {
  4425. //check Transaction active
  4426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4429. {
  4430. tempIndex = ((gun_index==2) ? 1: 0);
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4437. {
  4438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4439. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4440. {
  4441. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4442. {
  4443. reqSampleMeter[gun_index] = 1;
  4444. }
  4445. }
  4446. }// End for CHAdeMO
  4447. }
  4448. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CCS_QUANTITY; index++)
  4459. {
  4460. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4461. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4464. {
  4465. reqSampleMeter[gun_index] = 1;
  4466. }
  4467. }
  4468. } // End for CCS
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < GB_QUANTITY; index++)
  4481. {
  4482. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4483. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4484. {
  4485. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4486. {
  4487. reqSampleMeter[gun_index] = 1;
  4488. }
  4489. }
  4490. }// End for GB
  4491. }
  4492. else if(gunType[gun_index] == GUN_TYPE_DO)
  4493. {
  4494. tempIndex = gun_index;
  4495. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4496. {
  4497. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4498. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4499. {
  4500. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4501. {
  4502. reqSampleMeter[gun_index] = 1;
  4503. }
  4504. }
  4505. }
  4506. }
  4507. else
  4508. {
  4509. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4510. {
  4511. tempIndex = 2;
  4512. }
  4513. else
  4514. {
  4515. tempIndex = gun_index;
  4516. }
  4517. for (int index = 0; index < AC_QUANTITY; index++)
  4518. {
  4519. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4520. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4521. {
  4522. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4523. {
  4524. reqSampleMeter[gun_index] = 1;
  4525. }
  4526. }
  4527. }//End for AC
  4528. }
  4529. if(reqSampleMeter[gun_index] == 1)
  4530. {
  4531. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4532. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4533. //storeTempStopTransaction(gun_index);
  4534. reqSampleMeter[gun_index] = 0;
  4535. }
  4536. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4537. }
  4538. //==============================================
  4539. // Check Connector reserved
  4540. //==============================================
  4541. //===============================
  4542. // Check if Reserve is expired
  4543. //===============================
  4544. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4545. {
  4546. double diff_t;
  4547. struct tm tp;
  4548. // current time
  4549. time_t t = time(NULL);
  4550. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4551. tp.tm_isdst = -1;
  4552. time_t utc = mktime(&tp);
  4553. diff_t = difftime(utc, t);
  4554. if(diff_t <= 0)
  4555. {
  4556. DEBUG_INFO("reserve expired.\n");
  4557. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4558. }
  4559. }//END OF Check if Reserve is expired
  4560. //==========================================
  4561. // csu trigger FirmwareStatusNotificationReq
  4562. //==========================================
  4563. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4564. {
  4565. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4566. }
  4567. //==========================================
  4568. // csu trigger DiagnosticsStatusNotificationReq
  4569. //==========================================
  4570. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4571. {
  4572. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4573. }
  4574. //==========================================
  4575. // csu trigger CancelReservationConf
  4576. //==========================================
  4577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4578. {
  4579. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4580. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4581. }
  4582. //==========================================
  4583. // csu trigger ChangeAvailabilityConf
  4584. //==========================================
  4585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4586. {
  4587. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4588. }
  4589. //==========================================
  4590. // csu trigger UnlockConnectorConf
  4591. //==========================================
  4592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4593. {
  4594. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4595. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4596. }
  4597. //==========================================
  4598. // csu trigger ReserveNowConf
  4599. //==========================================
  4600. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4601. {
  4602. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4603. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4604. }
  4605. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4606. {
  4607. sendSignCertificateRequest();
  4608. }
  4609. }
  4610. }
  4611. //==========================================
  4612. // send request routine
  4613. //==========================================
  4614. int sendAuthorizeRequest(int gun_index)
  4615. {
  4616. mtrace();
  4617. int result = FAIL;
  4618. char message[100]={0};
  4619. char guid[37];
  4620. char tempdata[65]={0};
  4621. DEBUG_INFO("sendAuthorizeRequest...\n");
  4622. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4623. //Local Authorize
  4624. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4625. {
  4626. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4627. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4628. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4629. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4630. result = PASS;
  4631. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4632. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4633. authorizeRetryTimes = 0;
  4634. return result;
  4635. }
  4636. 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))||
  4637. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4638. {
  4639. // Query from cache
  4640. DEBUG_INFO("Authorize from cache.\n");
  4641. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4642. // Query from list
  4643. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4644. {
  4645. DEBUG_INFO("Authorize from list.\n");
  4646. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4647. }
  4648. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4649. {
  4650. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4651. {
  4652. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4653. }
  4654. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4655. {
  4656. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4657. }
  4658. if(!GetOcppConnStatus())
  4659. {
  4660. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4661. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4662. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4663. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4664. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4665. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4666. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4667. authorizeRetryTimes = 0;
  4668. return result;
  4669. }
  4670. }
  4671. else
  4672. {
  4673. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4674. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4675. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4676. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4677. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4678. else
  4679. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4680. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4681. result = PASS;
  4682. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4683. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4684. authorizeRetryTimes = 0;
  4685. return result;
  4686. }
  4687. }
  4688. //initialize struct Authorize
  4689. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4690. //get data from shared memory
  4691. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4692. random_uuid(guid);
  4693. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4694. LWS_Send(message);
  4695. sprintf(tempdata, "Authorize,%d", gun_index);
  4696. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4697. {
  4698. result = PASS;
  4699. DEBUG_INFO("Authorize mapItem pass\n");
  4700. }
  4701. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4702. return result;
  4703. }
  4704. int sendBootNotificationRequest(void)
  4705. {
  4706. mtrace();
  4707. int result = FAIL;
  4708. char message[500]={0}, payload[700]={0};
  4709. char guid[37]={0};
  4710. char tempdata[65]={0};
  4711. // Fill BootNotification fields
  4712. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4713. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4714. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4715. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4716. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4717. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4718. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4719. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4720. ShmOCPP16DataPH->ChargeBoxId
  4721. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4722. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4723. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4724. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4725. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4726. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4727. random_uuid(guid);
  4728. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4729. LWS_Send(message);
  4730. sprintf(tempdata, "BootNotification,0");
  4731. 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*/)
  4732. {
  4733. result = PASS;
  4734. }
  4735. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4736. strcpy(queuedata,message);
  4737. return result;
  4738. }
  4739. int sendDataTransferRequest(int gun_index)
  4740. {
  4741. mtrace();
  4742. char message[1000]={0};
  4743. char guid[37]={0};
  4744. char tempdata[65]={0};
  4745. int result = FAIL;
  4746. random_uuid(guid);
  4747. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4748. MESSAGE_TYPE_CALL,
  4749. guid,
  4750. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4751. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4752. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4753. LWS_Send(message);
  4754. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4755. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4756. {
  4757. result = PASS;
  4758. DEBUG_INFO("DataTransfer mapItem pass\n");
  4759. }
  4760. return result;
  4761. }
  4762. int sendUnplugByDataTransferRequest(int gun_index)
  4763. {
  4764. mtrace();
  4765. char message[1000]={0};
  4766. char guid[37]={0};
  4767. char tempdata[65]={0};
  4768. int result = FAIL;
  4769. random_uuid(guid);
  4770. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4771. (gun_index+1),
  4772. MESSAGE_TYPE_CALL,
  4773. guid,
  4774. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4775. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4776. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4777. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4778. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4779. {
  4780. result = PASS;
  4781. DEBUG_INFO("DataTransfer mapItem pass\n");
  4782. }
  4783. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4784. return result;
  4785. }
  4786. int sendDiagnosticsStatusNotificationRequest(char *status)
  4787. {
  4788. mtrace();
  4789. int result = FAIL;
  4790. char message[110]={0};
  4791. char guid[37]={0};
  4792. char tempdata[65]={0};
  4793. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4794. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4795. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4796. random_uuid(guid);
  4797. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4798. LWS_SendNow(message);
  4799. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4801. {
  4802. result = PASS;
  4803. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4804. }
  4805. //#ifdef SystemLogMessage
  4806. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4807. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4808. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4809. //#endif
  4810. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4811. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4812. //record status
  4813. if(strcmp(status,"Idle")==0)
  4814. {
  4815. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4816. }
  4817. else if(strcmp(status,"Uploaded")==0)
  4818. {
  4819. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4820. }
  4821. else if(strcmp(status,"UploadFailed")==0)
  4822. {
  4823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4824. }
  4825. else if(strcmp(status,"Uploading")==0)
  4826. {
  4827. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4828. }
  4829. return result;
  4830. }
  4831. int sendFirmwareStatusNotificationRequest(char *status)
  4832. {
  4833. mtrace();
  4834. int result = FAIL;
  4835. char message[110]={0};
  4836. char guid[37]={0};
  4837. char tempdata[65]={0};
  4838. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4839. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4840. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4841. random_uuid(guid);
  4842. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4843. LWS_SendNow(message);
  4844. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4845. 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*/)
  4846. {
  4847. result = PASS;
  4848. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4849. }
  4850. //#ifdef SystemLogMessage
  4851. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4852. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4853. //#endif
  4854. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4855. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4856. //record status
  4857. if(strcmp(status,"Downloaded")==0)
  4858. {
  4859. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4860. }
  4861. else if(strcmp(status,"DownloadFailed")==0)
  4862. {
  4863. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4864. }
  4865. else if(strcmp(status,"Downloading")==0)
  4866. {
  4867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4868. }
  4869. else if(strcmp(status,"Idle")==0)
  4870. {
  4871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4872. }
  4873. else if(strcmp(status,"InstallationFailed")==0)
  4874. {
  4875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4876. }
  4877. else if(strcmp(status,"Installing")==0)
  4878. {
  4879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4880. }
  4881. else if(strcmp(status,"Installed")==0)
  4882. {
  4883. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4884. }
  4885. return result;
  4886. }
  4887. int sendHeartbeatRequest(int gun_index)
  4888. {
  4889. mtrace();
  4890. int result = FAIL;
  4891. char message[80]={0};
  4892. char guid[37]={0};
  4893. char tempdata[65]={0};
  4894. random_uuid(guid);
  4895. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4896. , MESSAGE_TYPE_CALL
  4897. , guid );
  4898. LWS_Send(message);
  4899. sprintf(tempdata, "Heartbeat,%d", 0);
  4900. 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*/)
  4901. {
  4902. result = PASS;
  4903. }
  4904. return result;
  4905. }
  4906. int sendStartTransactionRequest(int gun_index)
  4907. {
  4908. mtrace();
  4909. int result = FAIL;
  4910. char message[250]={0};
  4911. char guid[37]={0};
  4912. struct timeval tmnow;
  4913. struct tm *tm;
  4914. char buf[28];//, usec_buf[6];
  4915. char tempdata[65]={0};
  4916. int tempIndex = 0;
  4917. DEBUG_INFO("sendStartTransactionRequest...\n");
  4918. gettimeofday(&tmnow, NULL);
  4919. time_t t;
  4920. t = time(NULL);
  4921. /*UTC time and date*/
  4922. tm = gmtime(&t);
  4923. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4924. #if 0 // remove temporally
  4925. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4926. strcat(buf,".");
  4927. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4928. strcat(buf,usec_buf);
  4929. #endif
  4930. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4931. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4932. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4933. // clear StartTransaction Response
  4934. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4935. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4936. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4937. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4938. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4939. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4940. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4941. {
  4942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4943. {
  4944. tempIndex = ((gun_index==2) ? 1: 0);
  4945. }
  4946. else
  4947. {
  4948. tempIndex = gun_index;
  4949. }
  4950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4951. {
  4952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4953. {
  4954. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4955. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4956. }
  4957. }
  4958. }
  4959. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4960. {
  4961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4962. {
  4963. tempIndex = ((gun_index==2) ? 1: 0);
  4964. }
  4965. else
  4966. {
  4967. tempIndex = gun_index;
  4968. }
  4969. for (int index = 0; index < CCS_QUANTITY; index++)
  4970. {
  4971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4972. {
  4973. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4974. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4975. }
  4976. }
  4977. }
  4978. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4979. {
  4980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4981. {
  4982. tempIndex = ((gun_index==2) ? 1: 0);
  4983. }
  4984. else
  4985. {
  4986. tempIndex = gun_index;
  4987. }
  4988. for (int index = 0; index < GB_QUANTITY; index++)
  4989. {
  4990. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4991. {
  4992. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4993. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4994. }
  4995. }
  4996. }
  4997. else if(gunType[gun_index] == GUN_TYPE_DO)
  4998. {
  4999. tempIndex = gun_index;
  5000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5003. {
  5004. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5005. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5006. }
  5007. }
  5008. }
  5009. else
  5010. {
  5011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5012. {
  5013. tempIndex = 2;
  5014. }
  5015. else
  5016. {
  5017. tempIndex = gun_index;
  5018. }
  5019. for (int index = 0; index < AC_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5022. {
  5023. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5024. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5025. }
  5026. }
  5027. }
  5028. random_uuid(guid);
  5029. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5030. {
  5031. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5032. , gun_index +1
  5033. , MESSAGE_TYPE_CALL
  5034. , guid
  5035. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5036. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5037. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5038. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5039. }
  5040. else
  5041. {
  5042. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5043. , gun_index +1
  5044. , MESSAGE_TYPE_CALL
  5045. , guid
  5046. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5047. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5048. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5049. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5050. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5051. }
  5052. #if 1
  5053. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5054. 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*/)
  5055. {
  5056. result = PASS;
  5057. }
  5058. #endif
  5059. strcpy(queuedata, message);
  5060. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5061. OCPP_insert_transaction_msg(YES, queuedata);
  5062. return result;
  5063. }
  5064. int sendStatusNotificationRequest(int gun_index)
  5065. {
  5066. mtrace();
  5067. int result = FAIL;
  5068. char message[600]={0};
  5069. char guid[37];
  5070. int currentStatus = 0;
  5071. struct timeval tmnow;
  5072. struct tm *tm;
  5073. char buf[28];//, usec_buf[6];
  5074. char tempdata[65]={0};
  5075. int tempIndex = 0;
  5076. uint8_t isStateChanged = TRUE;
  5077. uint8_t isContentIllegal = TRUE;
  5078. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5079. gettimeofday(&tmnow, NULL);
  5080. time_t t;
  5081. t = time(NULL);
  5082. /*UTC time and date*/
  5083. tm = gmtime(&t);
  5084. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5085. #if 0 // remove temporally
  5086. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5087. strcat(buf,".");
  5088. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5089. strcat(buf,usec_buf);
  5090. #endif
  5091. //printf("%s",buf);
  5092. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5093. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5094. // it's option
  5095. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5096. /*
  5097. enum _SYSTEM_STATUS
  5098. {
  5099. S_BOOTING = 0,
  5100. S_IDLE, = 1
  5101. S_AUTHORIZING, =2
  5102. S_REASSIGN_CHECK, =3
  5103. S_REASSIGN, =4
  5104. S_PRECHARGE, =5
  5105. S_PREPARING_FOR_EV, =6
  5106. S_PREPARING_FOR_EVSE, =7
  5107. S_CHARGING, =8
  5108. S_TERMINATING, =9
  5109. S_COMPLETE, =10
  5110. S_ALARM, =11
  5111. S_FAULT =12
  5112. }
  5113. */
  5114. //check Transaction active
  5115. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5116. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5117. {
  5118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5119. {
  5120. tempIndex = ((gun_index==2) ? 1: 0);
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5127. {
  5128. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5129. {
  5130. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5131. {
  5132. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5133. {
  5134. currentStatus = Preparing; //OCPP Status: Preparing
  5135. }
  5136. else
  5137. {
  5138. currentStatus = Available; //OCPP Status: Available
  5139. }
  5140. }
  5141. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5142. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5143. ) //S_PRECHARGE
  5144. {
  5145. currentStatus = Preparing; //OCPP Status: Preparing
  5146. }
  5147. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5148. {
  5149. currentStatus = Charging; //OCPP Status: Charging
  5150. }
  5151. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5152. {
  5153. currentStatus = Finishing; //OCPP Status: Finishing
  5154. }
  5155. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5156. {
  5157. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5158. }
  5159. 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
  5160. {
  5161. currentStatus = Unavailable; //OCPP Status: Unavailable
  5162. }
  5163. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5164. {
  5165. currentStatus = Faulted; //OCPP Status: Faulted
  5166. }
  5167. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5168. {
  5169. currentStatus = Reserved; //OCPP Status: Reserved
  5170. }
  5171. } //end of the same index
  5172. }//end of for CHAdeMO_QUANTITY
  5173. }
  5174. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5175. {
  5176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5177. {
  5178. tempIndex = ((gun_index==2) ? 1: 0);
  5179. }
  5180. else
  5181. {
  5182. tempIndex = gun_index;
  5183. }
  5184. for (int index = 0; index < CCS_QUANTITY; index++)
  5185. {
  5186. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5189. {
  5190. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5191. {
  5192. currentStatus = Preparing; //OCPP Status: Preparing
  5193. }
  5194. else
  5195. {
  5196. currentStatus = Available; //OCPP Status: Available
  5197. }
  5198. }
  5199. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5200. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5201. ) //S_PRECHARGE
  5202. {
  5203. currentStatus = Preparing; //OCPP Status: Preparing
  5204. }
  5205. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5206. {
  5207. currentStatus = Charging; //OCPP Status: Charging
  5208. }
  5209. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5210. {
  5211. currentStatus = Finishing; //OCPP Status: Finishing
  5212. }
  5213. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5214. {
  5215. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5216. }
  5217. 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
  5218. {
  5219. currentStatus = Unavailable; //OCPP Status : Unavailable
  5220. }
  5221. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5222. {
  5223. currentStatus = Faulted; //OCPP Status: Faulted
  5224. }
  5225. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5226. {
  5227. currentStatus = Reserved; //OCPP Status: Reserved
  5228. }
  5229. } //end of the same index
  5230. } // end of for CCS_QUANTITY
  5231. }
  5232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5233. {
  5234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5235. {
  5236. tempIndex = ((gun_index==2) ? 1: 0);
  5237. }
  5238. else
  5239. {
  5240. tempIndex = gun_index;
  5241. }
  5242. for (int index = 0; index < GB_QUANTITY; index++)
  5243. {
  5244. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5245. {
  5246. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5247. {
  5248. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5249. {
  5250. currentStatus = Preparing; //OCPP Status: Preparing
  5251. }
  5252. else
  5253. {
  5254. currentStatus = Available; //OCPP Status: Available
  5255. }
  5256. }
  5257. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5258. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5259. ) //S_PRECHARGE
  5260. {
  5261. currentStatus = Preparing; //OCPP Status: Preparing
  5262. }
  5263. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5264. {
  5265. currentStatus = Charging; //OCPP Status: Charging
  5266. }
  5267. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5268. {
  5269. currentStatus = Finishing; //OCPP Status: Finishing
  5270. }
  5271. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5272. {
  5273. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5274. }
  5275. 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
  5276. {
  5277. currentStatus = Unavailable; //OCPP Status: Unavailable
  5278. }
  5279. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5280. {
  5281. currentStatus = Faulted; //OCPP Status: Faulted
  5282. }
  5283. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5284. {
  5285. currentStatus = Reserved; //OCPP Status: Reserved
  5286. }
  5287. } //end of the same index
  5288. } // end of for GB_QUANTITY
  5289. }
  5290. else if(gunType[gun_index] == GUN_TYPE_DO)
  5291. {
  5292. tempIndex = gun_index;
  5293. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5294. {
  5295. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5298. {
  5299. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5300. {
  5301. currentStatus = Preparing; //OCPP Status: Preparing
  5302. }
  5303. else
  5304. {
  5305. currentStatus = Available; //OCPP Status: Available
  5306. }
  5307. }
  5308. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5309. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5310. ) //S_PRECHARGE
  5311. {
  5312. currentStatus = Preparing; //OCPP Status: Preparing
  5313. }
  5314. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5315. {
  5316. currentStatus = Charging; //OCPP Status: Charging
  5317. }
  5318. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5319. {
  5320. currentStatus = Finishing; //OCPP Status: Finishing
  5321. }
  5322. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5323. {
  5324. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5325. }
  5326. 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
  5327. {
  5328. currentStatus = Unavailable; //OCPP Status: Unavailable
  5329. }
  5330. 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
  5331. {
  5332. currentStatus = Faulted; //OCPP Status: Faulted
  5333. }
  5334. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5335. {
  5336. currentStatus = Reserved; //OCPP Status: Reserved
  5337. }
  5338. } //end of the same index
  5339. }
  5340. }
  5341. else
  5342. {
  5343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5344. {
  5345. tempIndex = 2;
  5346. }
  5347. else
  5348. {
  5349. tempIndex = gun_index;
  5350. }
  5351. for (int index = 0; index < AC_QUANTITY; index++)
  5352. {
  5353. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5354. {
  5355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5356. {
  5357. 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))
  5358. {
  5359. currentStatus = Preparing; //OCPP Status: Preparing
  5360. }
  5361. else
  5362. {
  5363. currentStatus = Available; //OCPP Status: Available
  5364. }
  5365. }
  5366. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5367. {
  5368. currentStatus = Preparing; //OCPP Status: Preparing
  5369. }
  5370. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5371. {
  5372. currentStatus = Charging; //OCPP Status: Charging
  5373. }
  5374. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5375. {
  5376. currentStatus = Finishing; //OCPP Status: Finishing
  5377. }
  5378. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5379. {
  5380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5381. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5382. else
  5383. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5384. }
  5385. 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
  5386. {
  5387. currentStatus = Unavailable; //OCPP Status: Unavailable
  5388. }
  5389. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5390. {
  5391. currentStatus = Faulted; //OCPP Status: Faulted
  5392. }
  5393. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5394. {
  5395. currentStatus = Reserved; //OCPP Status: Reserved
  5396. }
  5397. }//end of the same index
  5398. }//end of for AC_QUANTITY
  5399. }
  5400. //it's option
  5401. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5402. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5403. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5404. {
  5405. isStateChanged = FALSE;
  5406. }
  5407. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5408. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5409. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5410. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5411. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5412. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5413. isContentIllegal = TRUE;
  5414. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5415. {
  5416. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5417. {
  5418. isContentIllegal = FALSE;
  5419. break;
  5420. }
  5421. }
  5422. if(isContentIllegal)
  5423. {
  5424. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5425. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5426. }
  5427. random_uuid(guid);
  5428. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5429. , MESSAGE_TYPE_CALL
  5430. , guid
  5431. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5432. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5433. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5434. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5435. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5436. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5437. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5438. if((server_sign == TRUE) && isStateChanged)
  5439. {
  5440. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5441. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5442. LWS_Send(message);
  5443. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5444. 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*/)
  5445. {
  5446. //DEBUG_ERROR("statusNotification mapitem pass");
  5447. result = PASS;
  5448. }
  5449. }
  5450. else
  5451. {
  5452. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5453. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5454. result = PASS;
  5455. }
  5456. return result;
  5457. }
  5458. int sendStopTransactionRequest(int gun_index)
  5459. {
  5460. mtrace();
  5461. int result = FAIL;
  5462. //char message[1500]={0};
  5463. char guid[37]={0};
  5464. char tempdata[65]={0};
  5465. int tempIndex = 0;
  5466. char TempStopTransaction[256];
  5467. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5468. //int idx_sample=0;
  5469. DEBUG_INFO("sendStopTransactionRequest \n");
  5470. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5471. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5472. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5473. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5474. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5475. {
  5476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5477. {
  5478. tempIndex = ((gun_index==2) ? 1: 0);
  5479. }
  5480. else
  5481. {
  5482. tempIndex = gun_index;
  5483. }
  5484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5485. {
  5486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5487. {
  5488. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5489. }
  5490. }// END OF CHAdeMO_QUANTITY
  5491. }
  5492. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5493. {
  5494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5495. {
  5496. tempIndex = ((gun_index==2) ? 1: 0);
  5497. }
  5498. else
  5499. {
  5500. tempIndex = gun_index;
  5501. }
  5502. for (int index = 0; index < CCS_QUANTITY; index++)
  5503. {
  5504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5505. {
  5506. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5507. }
  5508. }// END OF CCS_QUANTITY
  5509. }
  5510. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5511. {
  5512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5513. {
  5514. tempIndex = ((gun_index==2) ? 1: 0);
  5515. }
  5516. else
  5517. {
  5518. tempIndex = gun_index;
  5519. }
  5520. for (int index = 0; index < GB_QUANTITY; index++)
  5521. {
  5522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5523. {
  5524. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5525. }
  5526. }// END OF GB_QUANTITY
  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. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5536. }
  5537. }// END OF GB_QUANTITY
  5538. }
  5539. else
  5540. {
  5541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5542. {
  5543. tempIndex = 2;
  5544. }
  5545. else
  5546. {
  5547. tempIndex = gun_index;
  5548. }
  5549. for (int index = 0; index < AC_QUANTITY; index++)
  5550. {
  5551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5552. {
  5553. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5554. }
  5555. }// END OF AC_QUANTITY
  5556. }
  5557. //====================================== Stop Transaction Time =====================================================
  5558. struct timeval tmnow;
  5559. struct tm *tm;
  5560. char buf[28];//, usec_buf[6];
  5561. gettimeofday(&tmnow, NULL);
  5562. time_t t;
  5563. t = time(NULL);
  5564. /*UTC time and date*/
  5565. tm = gmtime(&t);
  5566. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5568. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5569. random_uuid(guid);
  5570. /***********************************transactionData******************************************************/
  5571. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5573. //=================================
  5574. // Transaction_Begin
  5575. //=================================
  5576. //=================================
  5577. // Transaction_End
  5578. //=================================
  5579. // ================================= Current.Import L1 ===============================================
  5580. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5581. {
  5582. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5584. {
  5585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5586. {
  5587. tempIndex = ((gun_index==2) ? 1: 0);
  5588. }
  5589. else
  5590. {
  5591. tempIndex = gun_index;
  5592. }
  5593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5594. {
  5595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5596. {
  5597. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5598. }
  5599. }// End of for CHAdeMO_QUANTITY
  5600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5601. }
  5602. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5603. {
  5604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5605. {
  5606. tempIndex = ((gun_index==2) ? 1: 0);
  5607. }
  5608. else
  5609. {
  5610. tempIndex = gun_index;
  5611. }
  5612. for (int index = 0; index < CCS_QUANTITY; index++)
  5613. {
  5614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5615. {
  5616. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5617. }
  5618. }// End of for CCS_QUANTITY
  5619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5620. }
  5621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5622. {
  5623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5624. {
  5625. tempIndex = ((gun_index==2) ? 1: 0);
  5626. }
  5627. else
  5628. {
  5629. tempIndex = gun_index;
  5630. }
  5631. for (int index = 0; index < GB_QUANTITY; index++)
  5632. {
  5633. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5634. {
  5635. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5636. }
  5637. }// End of for GB_QUANTITY
  5638. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5639. }
  5640. else if(gunType[gun_index] == GUN_TYPE_DO)
  5641. {
  5642. tempIndex = gun_index;
  5643. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5648. }
  5649. }
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5651. }
  5652. else
  5653. {
  5654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5655. {
  5656. tempIndex = 2;
  5657. }
  5658. else
  5659. {
  5660. tempIndex = gun_index;
  5661. }
  5662. for (int index = 0; index < AC_QUANTITY; index++)
  5663. {
  5664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5665. {
  5666. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5667. }
  5668. }// End of for AC_QUANTITY
  5669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5670. }
  5671. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5673. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5676. }
  5677. // ================================= Energy.Active.Import.Interval ==============================================
  5678. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5679. {
  5680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5682. {
  5683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5684. {
  5685. tempIndex = ((gun_index==2) ? 1: 0);
  5686. }
  5687. else
  5688. {
  5689. tempIndex = gun_index;
  5690. }
  5691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5692. {
  5693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5694. {
  5695. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5696. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5697. }
  5698. }// END OF CHAdeMO_QUANTITY
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5700. }
  5701. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5702. {
  5703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5704. {
  5705. tempIndex = ((gun_index==2) ? 1: 0);
  5706. }
  5707. else
  5708. {
  5709. tempIndex = gun_index;
  5710. }
  5711. for (int index = 0; index < CCS_QUANTITY; index++)
  5712. {
  5713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5714. {
  5715. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5716. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5717. }
  5718. }// END OF CCS_QUANTITY
  5719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5720. }
  5721. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5722. {
  5723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5724. {
  5725. tempIndex = ((gun_index==2) ? 1: 0);
  5726. }
  5727. else
  5728. {
  5729. tempIndex = gun_index;
  5730. }
  5731. for (int index = 0; index < GB_QUANTITY; index++)
  5732. {
  5733. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5734. {
  5735. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5736. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5737. }
  5738. }// END OF GB_QUANTITY
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5740. }
  5741. else if(gunType[gun_index] == GUN_TYPE_DO)
  5742. {
  5743. tempIndex = gun_index;
  5744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5745. {
  5746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5747. {
  5748. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5749. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5750. }
  5751. }
  5752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5753. }
  5754. else
  5755. {
  5756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5757. {
  5758. tempIndex = 2;
  5759. }
  5760. else
  5761. {
  5762. tempIndex = gun_index;
  5763. }
  5764. for (int index = 0; index < AC_QUANTITY; index++)
  5765. {
  5766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5767. {
  5768. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5769. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5770. }
  5771. }// END OF AC_QUANTITY
  5772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5773. }
  5774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5775. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5777. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5779. }
  5780. //=================================== Power.Active.Import ==================================================
  5781. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5782. {
  5783. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5784. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5787. {
  5788. tempIndex = ((gun_index==2) ? 1: 0);
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5799. }
  5800. } // End for CHAdeMO_QUANTITY
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5802. }
  5803. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5804. {
  5805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5806. {
  5807. tempIndex = ((gun_index==2) ? 1: 0);
  5808. }
  5809. else
  5810. {
  5811. tempIndex = gun_index;
  5812. }
  5813. for (int index = 0; index < CCS_QUANTITY; index++)
  5814. {
  5815. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5816. {
  5817. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5818. }
  5819. } // END for CCS_QUANTITY
  5820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5821. }
  5822. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5823. {
  5824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5825. {
  5826. tempIndex = ((gun_index==2) ? 1: 0);
  5827. }
  5828. else
  5829. {
  5830. tempIndex = gun_index;
  5831. }
  5832. for (int index = 0; index < GB_QUANTITY; index++)
  5833. {
  5834. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5835. {
  5836. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5837. }
  5838. }// END for GB_QUANTITY
  5839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5840. }
  5841. else if(gunType[gun_index] == GUN_TYPE_DO)
  5842. {
  5843. tempIndex = gun_index;
  5844. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5845. {
  5846. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5847. {
  5848. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5849. }
  5850. }
  5851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5852. }
  5853. else
  5854. {
  5855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5856. {
  5857. tempIndex = 2;
  5858. }
  5859. else
  5860. {
  5861. tempIndex = gun_index;
  5862. }
  5863. for (int index = 0; index < AC_QUANTITY; index++)
  5864. {
  5865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5866. {
  5867. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5868. }
  5869. } // END for AC_QUANTITY
  5870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5871. }
  5872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5875. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5877. }
  5878. //============================ Voltage L1 ====================================
  5879. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5880. {
  5881. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5882. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5885. {
  5886. tempIndex = ((gun_index==2) ? 1: 0);
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5895. {
  5896. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5897. }
  5898. } // END OF FOR CHAdeMO_QUANTITY
  5899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5900. }
  5901. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5902. {
  5903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5904. {
  5905. tempIndex = ((gun_index==2) ? 1: 0);
  5906. }
  5907. else
  5908. {
  5909. tempIndex = gun_index;
  5910. }
  5911. for (int index = 0; index < CCS_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5916. }
  5917. } // END OF FOR CCS_QUANTITY
  5918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5919. }
  5920. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5923. {
  5924. tempIndex = ((gun_index==2) ? 1: 0);
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < GB_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5935. }
  5936. } // END OF FOR GB_QUANTITY
  5937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5938. }
  5939. else if(gunType[gun_index] == GUN_TYPE_DO)
  5940. {
  5941. tempIndex = gun_index;
  5942. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5943. {
  5944. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5945. {
  5946. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5947. }
  5948. }
  5949. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5950. }
  5951. else
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5954. {
  5955. tempIndex = 2;
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < AC_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5964. {
  5965. 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
  5966. }
  5967. } // END OF FOR AC_QUANTITY
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5969. }
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5975. }
  5976. //====================== End SoC ================================
  5977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5978. {
  5979. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5980. 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))
  5981. {
  5982. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5983. {
  5984. tempIndex = ((gun_index==2) ? 1: 0);
  5985. }
  5986. else
  5987. {
  5988. tempIndex = gun_index;
  5989. }
  5990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5991. {
  5992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5993. {
  5994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5995. {
  5996. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5997. }
  5998. }
  5999. }
  6000. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6001. {
  6002. for (int index = 0; index < CCS_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6005. {
  6006. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6007. }
  6008. }
  6009. }
  6010. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6011. {
  6012. for (int index = 0; index < GB_QUANTITY; index++)
  6013. {
  6014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6015. {
  6016. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6017. }
  6018. }
  6019. }
  6020. else if(gunType[gun_index] == GUN_TYPE_DO)
  6021. {
  6022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6027. }
  6028. }
  6029. }
  6030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6033. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6034. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6036. } // END FOR DC CASE
  6037. }
  6038. // ================================= Current.Import L2 ===============================================
  6039. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6040. {
  6041. // AC 3 phse L2 current
  6042. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6043. {
  6044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6045. {
  6046. tempIndex = 2;
  6047. }
  6048. else
  6049. {
  6050. tempIndex = gun_index;
  6051. }
  6052. for (int index = 0; index < AC_QUANTITY; index++)
  6053. {
  6054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6055. {
  6056. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6057. }
  6058. }// End of for AC_QUANTITY
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6060. }
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6066. }
  6067. // ================================= Current.Import L3 ===============================================
  6068. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6069. {
  6070. // AC 3 phse L3 current
  6071. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6072. {
  6073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6074. {
  6075. tempIndex = 2;
  6076. }
  6077. else
  6078. {
  6079. tempIndex = gun_index;
  6080. }
  6081. for (int index = 0; index < AC_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6084. {
  6085. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6086. }
  6087. }// End of for AC_QUANTITY
  6088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6089. }
  6090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6095. }
  6096. //============================ Voltage L2 ====================================
  6097. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6098. {
  6099. // AC 3 phse L2 voltage
  6100. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6101. {
  6102. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6103. {
  6104. tempIndex = 2;
  6105. }
  6106. else
  6107. {
  6108. tempIndex = gun_index;
  6109. }
  6110. for (int index = 0; index < AC_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6113. {
  6114. 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
  6115. }
  6116. } // END OF FOR AC_QUANTITY
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6118. }
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6124. }
  6125. //============================ Voltage L3 ====================================
  6126. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6127. {
  6128. // AC 3 phse L3 voltage
  6129. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6130. {
  6131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6132. {
  6133. tempIndex = 2;
  6134. }
  6135. else
  6136. {
  6137. tempIndex = gun_index;
  6138. }
  6139. for (int index = 0; index < AC_QUANTITY; index++)
  6140. {
  6141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6142. {
  6143. 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
  6144. }
  6145. } // END OF FOR AC_QUANTITY
  6146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6147. }
  6148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6153. }
  6154. //====================== Start SoC ================================
  6155. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6156. {
  6157. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6158. 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))
  6159. {
  6160. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6161. {
  6162. tempIndex = ((gun_index==2) ? 1: 0);
  6163. }
  6164. else
  6165. {
  6166. tempIndex = gun_index;
  6167. }
  6168. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6169. {
  6170. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6171. {
  6172. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6173. {
  6174. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6175. }
  6176. }
  6177. }
  6178. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6179. {
  6180. for (int index = 0; index < CCS_QUANTITY; index++)
  6181. {
  6182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6183. {
  6184. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6185. }
  6186. }
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6189. {
  6190. for (int index = 0; index < GB_QUANTITY; index++)
  6191. {
  6192. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6193. {
  6194. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6195. }
  6196. }
  6197. }
  6198. else if(gunType[gun_index] == GUN_TYPE_DO)
  6199. {
  6200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6201. {
  6202. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6203. {
  6204. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6205. }
  6206. }
  6207. }
  6208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6214. } // END FOR DC CASE
  6215. }
  6216. //================================================ Message create ====================================================
  6217. json_object *StopTransaction = json_object_new_object();
  6218. json_object *transactionDatas = json_object_new_array();
  6219. json_object *sampledValues = json_object_new_array();
  6220. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6221. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6222. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6223. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6224. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6225. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6226. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6227. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6228. {
  6229. json_object *transactionData = json_object_new_object();
  6230. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6231. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6232. {
  6233. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6234. {
  6235. json_object *sampledValue = json_object_new_object();
  6236. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6237. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6238. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6239. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6240. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6241. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6242. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6243. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6244. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6245. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6246. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6247. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6248. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6249. json_object_array_add(sampledValues, sampledValue);
  6250. }
  6251. }
  6252. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6253. json_object_array_add(transactionDatas, transactionData);
  6254. }
  6255. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6256. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6257. ,MESSAGE_TYPE_CALL
  6258. ,guid
  6259. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6260. json_object_put(StopTransaction);
  6261. #if 1 // for TempStopTransaction
  6262. //Delete TempStopTransaction
  6263. if((access(TempStopTransaction,F_OK))!=-1)
  6264. {
  6265. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6266. }
  6267. #endif
  6268. #if 1
  6269. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6270. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6271. {
  6272. result = PASS;
  6273. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6274. }
  6275. #endif
  6276. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6277. OCPP_insert_transaction_msg(NO, queuedata);
  6278. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6279. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6280. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6281. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6282. {
  6283. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6284. }
  6285. //for test
  6286. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6287. return result;
  6288. }
  6289. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6290. {
  6291. mtrace();
  6292. int result = FAIL;
  6293. char guid[37]={0};
  6294. char tempdata[65]={0};
  6295. int tempIndex = 0;
  6296. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6297. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6298. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6299. //set value
  6300. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6301. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6302. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6303. -1);
  6304. random_uuid(guid);
  6305. //UTC Date time
  6306. struct timeval tmnow;
  6307. struct tm *tm;
  6308. char buf[28];//, usec_buf[6];
  6309. gettimeofday(&tmnow, NULL);
  6310. time_t t;
  6311. t = time(NULL);
  6312. /*UTC time and date*/
  6313. tm = gmtime(&t);
  6314. if(dataType == ReadingContext_Sample_Clock)
  6315. {
  6316. struct tm *tmTarget;
  6317. struct timeb tbTarget;
  6318. tbTarget.time = mktime(tm);
  6319. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6320. tmTarget = gmtime(&tbTarget.time);
  6321. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6322. }
  6323. else
  6324. {
  6325. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6326. }
  6327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6328. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6329. //********************************(1)Current.Import L1************************************************/
  6330. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6331. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6332. (dataType == ReadingContext_Trigger))
  6333. {
  6334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < CCS_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6369. }
  6370. }
  6371. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6376. {
  6377. tempIndex = ((gun_index==2) ? 1: 0);
  6378. }
  6379. else
  6380. {
  6381. tempIndex = gun_index;
  6382. }
  6383. for (int index = 0; index < GB_QUANTITY; index++)
  6384. {
  6385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6386. {
  6387. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6388. }
  6389. }
  6390. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6391. }
  6392. else if(gunType[gun_index] == GUN_TYPE_DO)
  6393. {
  6394. tempIndex = gun_index;
  6395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6398. {
  6399. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6400. }
  6401. }
  6402. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6403. }
  6404. else
  6405. {
  6406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6407. {
  6408. tempIndex = 2;
  6409. }
  6410. else
  6411. {
  6412. tempIndex = gun_index;
  6413. }
  6414. for (int index = 0; index < AC_QUANTITY; index++)
  6415. {
  6416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6417. {
  6418. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6419. }
  6420. }
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6422. }
  6423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6428. }
  6429. //********************************(2)Energy.Active.Import.Register ************************************************/
  6430. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6431. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6432. (dataType == ReadingContext_Trigger))
  6433. {
  6434. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6435. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6436. {
  6437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6438. {
  6439. tempIndex = ((gun_index==2) ? 1: 0);
  6440. }
  6441. else
  6442. {
  6443. tempIndex = gun_index;
  6444. }
  6445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6450. }
  6451. }
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6453. }
  6454. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6455. {
  6456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6457. {
  6458. tempIndex = ((gun_index==2) ? 1: 0);
  6459. }
  6460. else
  6461. {
  6462. tempIndex = gun_index;
  6463. }
  6464. for (int index = 0; index < CCS_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6469. }
  6470. }
  6471. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6472. }
  6473. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6474. {
  6475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6476. {
  6477. tempIndex = ((gun_index==2) ? 1: 0);
  6478. }
  6479. else
  6480. {
  6481. tempIndex = gun_index;
  6482. }
  6483. for (int index = 0; index < GB_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6486. {
  6487. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6488. }
  6489. }
  6490. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6491. }
  6492. else if(gunType[gun_index] == GUN_TYPE_DO)
  6493. {
  6494. tempIndex = gun_index;
  6495. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6496. {
  6497. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6498. {
  6499. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6500. }
  6501. }
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6503. }
  6504. else
  6505. {
  6506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6507. {
  6508. tempIndex = 2;
  6509. }
  6510. else
  6511. {
  6512. tempIndex = gun_index;
  6513. }
  6514. for (int index = 0; index < AC_QUANTITY; index++)
  6515. {
  6516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6517. {
  6518. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6519. }
  6520. }
  6521. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6522. }
  6523. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6524. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6525. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6526. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6527. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6528. }
  6529. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6530. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6531. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6532. (dataType == ReadingContext_Trigger))
  6533. {
  6534. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6535. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6536. {
  6537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6538. {
  6539. tempIndex = ((gun_index==2) ? 1: 0);
  6540. }
  6541. else
  6542. {
  6543. tempIndex = gun_index;
  6544. }
  6545. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6548. {
  6549. if(dataType == ReadingContext_Sample_Clock)
  6550. {
  6551. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6552. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6553. }
  6554. else if(dataType == ReadingContext_Sample_Periodic)
  6555. {
  6556. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6557. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6558. }
  6559. else
  6560. {
  6561. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6562. }
  6563. }
  6564. } // END OF FOR CHAdeMO_QUANTITY
  6565. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6566. }
  6567. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6568. {
  6569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6570. {
  6571. tempIndex = ((gun_index==2) ? 1: 0);
  6572. }
  6573. else
  6574. {
  6575. tempIndex = gun_index;
  6576. }
  6577. for (int index = 0; index < CCS_QUANTITY; index++)
  6578. {
  6579. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6580. {
  6581. if(dataType == ReadingContext_Sample_Clock)
  6582. {
  6583. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6584. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6585. }
  6586. else if(dataType == ReadingContext_Sample_Periodic)
  6587. {
  6588. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6589. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6590. }
  6591. else
  6592. {
  6593. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6594. }
  6595. }
  6596. } // END OF CCS_QUANTITY
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6598. }
  6599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6600. {
  6601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6602. {
  6603. tempIndex = ((gun_index==2) ? 1: 0);
  6604. }
  6605. else
  6606. {
  6607. tempIndex = gun_index;
  6608. }
  6609. for (int index = 0; index < GB_QUANTITY; index++)
  6610. {
  6611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6612. {
  6613. if(dataType == ReadingContext_Sample_Clock)
  6614. {
  6615. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6616. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6617. }
  6618. else if(dataType == ReadingContext_Sample_Periodic)
  6619. {
  6620. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6621. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6622. }
  6623. else
  6624. {
  6625. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6626. }
  6627. }
  6628. } // END OF GB_QUANTITY
  6629. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6630. }
  6631. else if(gunType[gun_index] == GUN_TYPE_DO)
  6632. {
  6633. tempIndex = gun_index;
  6634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6635. {
  6636. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6637. {
  6638. if(dataType == ReadingContext_Sample_Clock)
  6639. {
  6640. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6641. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6642. }
  6643. else if(dataType == ReadingContext_Sample_Periodic)
  6644. {
  6645. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6646. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6647. }
  6648. else
  6649. {
  6650. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6651. }
  6652. }
  6653. }
  6654. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6655. }
  6656. else
  6657. {
  6658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6659. {
  6660. tempIndex = 2;
  6661. }
  6662. else
  6663. {
  6664. tempIndex = gun_index;
  6665. }
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6669. {
  6670. if(dataType == ReadingContext_Sample_Clock)
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6673. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6674. }
  6675. else if(dataType == ReadingContext_Sample_Periodic)
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6678. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6679. }
  6680. else
  6681. {
  6682. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6683. }
  6684. }
  6685. }
  6686. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6687. }
  6688. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6689. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6690. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6691. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6693. }
  6694. //********************************(4)Power.Active.Import************************************************/
  6695. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6696. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6697. (dataType == ReadingContext_Trigger))
  6698. {
  6699. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6700. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6701. {
  6702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6703. {
  6704. tempIndex = ((gun_index==2) ? 1: 0);
  6705. }
  6706. else
  6707. {
  6708. tempIndex = gun_index;
  6709. }
  6710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6711. {
  6712. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6713. {
  6714. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6715. }
  6716. } // END OF FOR
  6717. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6718. }
  6719. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6720. {
  6721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6722. {
  6723. tempIndex = ((gun_index==2) ? 1: 0);
  6724. }
  6725. else
  6726. {
  6727. tempIndex = gun_index;
  6728. }
  6729. for (int index = 0; index < CCS_QUANTITY; index++)
  6730. {
  6731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6732. {
  6733. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6734. }
  6735. }
  6736. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6737. }
  6738. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6739. {
  6740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6741. {
  6742. tempIndex = ((gun_index==2) ? 1: 0);
  6743. }
  6744. else
  6745. {
  6746. tempIndex = gun_index;
  6747. }
  6748. for (int index = 0; index < GB_QUANTITY; index++)
  6749. {
  6750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6751. {
  6752. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6753. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6754. }
  6755. }
  6756. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6757. }
  6758. else if(gunType[gun_index] == GUN_TYPE_DO)
  6759. {
  6760. tempIndex = gun_index;
  6761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6764. {
  6765. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6766. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6767. }
  6768. }
  6769. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6770. }
  6771. else
  6772. {
  6773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6774. {
  6775. tempIndex = 2;
  6776. }
  6777. else
  6778. {
  6779. tempIndex = gun_index;
  6780. }
  6781. for (int index = 0; index < AC_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6784. {
  6785. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6786. }
  6787. }
  6788. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6789. }
  6790. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6791. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6792. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6793. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6794. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6795. }
  6796. //***********************************************(5)VOLTAGE L1******************************************************/
  6797. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6798. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6799. (dataType == ReadingContext_Trigger))
  6800. {
  6801. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6803. {
  6804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6805. {
  6806. tempIndex = ((gun_index==2) ? 1: 0);
  6807. }
  6808. else
  6809. {
  6810. tempIndex = gun_index;
  6811. }
  6812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6815. {
  6816. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6817. }
  6818. }
  6819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6820. }
  6821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6822. {
  6823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6824. {
  6825. tempIndex = ((gun_index==2) ? 1: 0);
  6826. }
  6827. else
  6828. {
  6829. tempIndex = gun_index;
  6830. }
  6831. for (int index = 0; index < CCS_QUANTITY; index++)
  6832. {
  6833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6834. {
  6835. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6836. }
  6837. }
  6838. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6839. }
  6840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6841. {
  6842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6843. {
  6844. tempIndex = ((gun_index==2) ? 1: 0);
  6845. }
  6846. else
  6847. {
  6848. tempIndex = gun_index;
  6849. }
  6850. for (int index = 0; index < GB_QUANTITY; index++)
  6851. {
  6852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6853. {
  6854. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6855. }
  6856. }
  6857. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6858. }
  6859. else if(gunType[gun_index] == GUN_TYPE_DO)
  6860. {
  6861. tempIndex = gun_index;
  6862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6863. {
  6864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6865. {
  6866. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6867. }
  6868. }
  6869. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6870. }
  6871. else
  6872. {
  6873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6874. {
  6875. tempIndex = 2;
  6876. }
  6877. else
  6878. {
  6879. tempIndex = gun_index;
  6880. }
  6881. for (int index = 0; index < AC_QUANTITY; index++)
  6882. {
  6883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6884. {
  6885. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6886. }
  6887. }
  6888. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6889. }
  6890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6895. }
  6896. //***********************************************(6)SOC******************************************************/
  6897. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6898. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6899. (dataType == ReadingContext_Trigger))
  6900. {
  6901. 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))
  6902. {
  6903. //idx_sample=5;
  6904. //sampledValue = NULL;
  6905. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6906. {
  6907. tempIndex = ((gun_index==2) ? 1: 0);
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6914. {
  6915. //tempIndex = ((gun_index==2) ? 1: 0);
  6916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6921. }
  6922. }
  6923. }
  6924. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6925. {
  6926. //tempIndex = ((gun_index==2) ? 1: 0);
  6927. for (int index = 0; index < CCS_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6932. }
  6933. }
  6934. }
  6935. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6936. {
  6937. //tempIndex = ((gun_index==2) ? 1: 0);
  6938. for (int index = 0; index < GB_QUANTITY; index++)
  6939. {
  6940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6941. {
  6942. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6943. }
  6944. }
  6945. }
  6946. else if(gunType[gun_index] == GUN_TYPE_DO)
  6947. {
  6948. //tempIndex = ((gun_index==2) ? 1: 0);
  6949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6952. {
  6953. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6954. }
  6955. }
  6956. }
  6957. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6958. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6959. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6960. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6961. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6962. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6963. }
  6964. }
  6965. //********************************(7)Current.Import L2************************************************/
  6966. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6967. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6968. (dataType == ReadingContext_Trigger))
  6969. {
  6970. // Only for AC 3 phase
  6971. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6972. {
  6973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6974. {
  6975. tempIndex = 2;
  6976. }
  6977. else
  6978. {
  6979. tempIndex = gun_index;
  6980. }
  6981. for (int index = 0; index < AC_QUANTITY; index++)
  6982. {
  6983. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6984. {
  6985. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6986. }
  6987. }
  6988. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6989. }
  6990. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6995. }
  6996. //********************************(8)Current.Import L3************************************************/
  6997. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6998. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6999. (dataType == ReadingContext_Trigger))
  7000. {
  7001. // Only for AC 3 phase
  7002. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7005. {
  7006. tempIndex = 2;
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < AC_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7015. {
  7016. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7017. }
  7018. }
  7019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7020. }
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7023. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7026. }
  7027. //***********************************************(9)VOLTAGE L2******************************************************/
  7028. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7029. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7030. (dataType == ReadingContext_Trigger))
  7031. {
  7032. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7035. {
  7036. tempIndex = 2;
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7047. }
  7048. }
  7049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7050. }
  7051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7056. }
  7057. //***********************************************(10)VOLTAGE L3******************************************************/
  7058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7060. (dataType == ReadingContext_Trigger))
  7061. {
  7062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7065. {
  7066. tempIndex = 2;
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < AC_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7075. {
  7076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7077. }
  7078. }
  7079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7080. }
  7081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7086. }
  7087. //***********************************************(11)Current.Offered******************************************************/
  7088. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7089. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7090. (dataType == ReadingContext_Trigger))
  7091. {
  7092. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7094. {
  7095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7096. {
  7097. tempIndex = ((gun_index==2) ? 1: 0);
  7098. }
  7099. else
  7100. {
  7101. tempIndex = gun_index;
  7102. }
  7103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7104. {
  7105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7106. {
  7107. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7108. }
  7109. } // END OF FOR CHAdeMO_QUANTITY
  7110. }
  7111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7112. {
  7113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7114. {
  7115. tempIndex = ((gun_index==2) ? 1: 0);
  7116. }
  7117. else
  7118. {
  7119. tempIndex = gun_index;
  7120. }
  7121. for (int index = 0; index < CCS_QUANTITY; index++)
  7122. {
  7123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7124. {
  7125. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7126. }
  7127. } // END OF CCS_QUANTITY
  7128. }
  7129. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7130. {
  7131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7132. {
  7133. tempIndex = ((gun_index==2) ? 1: 0);
  7134. }
  7135. else
  7136. {
  7137. tempIndex = gun_index;
  7138. }
  7139. for (int index = 0; index < GB_QUANTITY; index++)
  7140. {
  7141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7142. {
  7143. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7144. }
  7145. } // END OF GB_QUANTITY
  7146. }
  7147. else if(gunType[gun_index] == GUN_TYPE_DO)
  7148. {
  7149. tempIndex = gun_index;
  7150. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7151. {
  7152. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7153. {
  7154. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7155. }
  7156. }
  7157. }
  7158. else
  7159. {
  7160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7161. {
  7162. tempIndex = 2;
  7163. }
  7164. else
  7165. {
  7166. tempIndex = gun_index;
  7167. }
  7168. for (int index = 0; index < AC_QUANTITY; index++)
  7169. {
  7170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7171. {
  7172. uint16_t currentOffer;
  7173. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7174. {
  7175. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7176. }
  7177. else
  7178. {
  7179. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7180. }
  7181. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7182. }
  7183. }
  7184. }
  7185. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7187. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7188. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7189. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7190. }
  7191. //***********************************************(12)Power.Offered******************************************************/
  7192. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7193. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7194. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7195. {
  7196. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7197. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7198. {
  7199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7200. {
  7201. tempIndex = ((gun_index==2) ? 1: 0);
  7202. }
  7203. else
  7204. {
  7205. tempIndex = gun_index;
  7206. }
  7207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7208. {
  7209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7210. {
  7211. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7212. }
  7213. } // END OF FOR CHAdeMO_QUANTITY
  7214. }
  7215. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7216. {
  7217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7218. {
  7219. tempIndex = ((gun_index==2) ? 1: 0);
  7220. }
  7221. else
  7222. {
  7223. tempIndex = gun_index;
  7224. }
  7225. for (int index = 0; index < CCS_QUANTITY; index++)
  7226. {
  7227. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7228. {
  7229. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7230. }
  7231. } // END OF CCS_QUANTITY
  7232. }
  7233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7234. {
  7235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7236. {
  7237. tempIndex = ((gun_index==2) ? 1: 0);
  7238. }
  7239. else
  7240. {
  7241. tempIndex = gun_index;
  7242. }
  7243. for (int index = 0; index < GB_QUANTITY; index++)
  7244. {
  7245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7246. {
  7247. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7248. }
  7249. } // END OF GB_QUANTITY
  7250. }
  7251. else if(gunType[gun_index] == GUN_TYPE_DO)
  7252. {
  7253. tempIndex = gun_index;
  7254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7255. {
  7256. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7257. {
  7258. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7259. }
  7260. }
  7261. }
  7262. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7263. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7264. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7265. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7266. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7267. }
  7268. // Message create ====================================================================================================
  7269. if(TRUE)
  7270. {
  7271. json_object *MeterValueReq = json_object_new_object();
  7272. json_object *MeterValues = json_object_new_array();
  7273. json_object *sampledValues = json_object_new_array();
  7274. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7275. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7276. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7277. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7278. {
  7279. json_object *MeterValue = json_object_new_object();
  7280. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7281. {
  7282. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7283. {
  7284. json_object *sampledValue = json_object_new_object();
  7285. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7286. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7287. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7288. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7289. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7290. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7291. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7292. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7293. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7294. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7295. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7296. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7297. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7298. json_object_array_add(sampledValues, sampledValue);
  7299. }
  7300. }
  7301. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7302. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7303. json_object_array_add(MeterValues, MeterValue);
  7304. }
  7305. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7306. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7307. ,gun_index + 1
  7308. ,MESSAGE_TYPE_CALL
  7309. ,guid
  7310. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7311. json_object_put(MeterValueReq);
  7312. }
  7313. // Put request guid to hash map
  7314. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7315. 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*/)
  7316. {
  7317. result = PASS;
  7318. //DEBUG_INFO("MeterValues mapitem pass\n");
  7319. }
  7320. if((dataType != ReadingContext_Trigger) &&
  7321. (dataType != ReadingContext_Sample_Clock) &&
  7322. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7323. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7324. else
  7325. {
  7326. if(FirstHeartBeat)
  7327. LWS_Send(queuedata +2);
  7328. }
  7329. return result;
  7330. }
  7331. int sendLogStatusNotificationRequest(char *status)
  7332. {
  7333. mtrace();
  7334. int result = PASS;
  7335. char message[4096]={0};
  7336. char guid[37]={0};
  7337. char tempdata[128]={0};
  7338. json_object *LogStatusNotification = json_object_new_object();
  7339. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7340. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7341. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7342. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7343. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7344. random_uuid(guid);
  7345. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7346. json_object_put(LogStatusNotification);
  7347. LWS_Send(message);
  7348. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7349. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7350. {
  7351. result = PASS;
  7352. }
  7353. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7354. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7355. return result;
  7356. }
  7357. int sendSecurityEventNotificationRequest()
  7358. {
  7359. mtrace();
  7360. int result = PASS;
  7361. char message[4096]={0};
  7362. char guid[37]={0};
  7363. char tempdata[128]={0};
  7364. json_object *SecurityEventNotification = json_object_new_object();
  7365. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7366. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7367. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7368. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7369. random_uuid(guid);
  7370. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7371. json_object_put(SecurityEventNotification);
  7372. LWS_Send(message);
  7373. sprintf(tempdata, "SecurityEventNotification,0");
  7374. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7375. {
  7376. result = PASS;
  7377. }
  7378. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7379. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7380. return result;
  7381. }
  7382. int sendSignCertificateRequest()
  7383. {
  7384. mtrace();
  7385. int result = PASS;
  7386. char message[4096]={0};
  7387. char guid[37]={0};
  7388. char tempdata[128]={0};
  7389. json_object *SignCertificate = json_object_new_object();
  7390. DEBUG_INFO("sendSignCertificateRequest...\n");
  7391. // Read csr file content
  7392. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7393. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7394. char *line = NULL;
  7395. size_t len = 0;
  7396. while(getline(&line, &len, fp) != -1)
  7397. {
  7398. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7399. {
  7400. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7401. }
  7402. }
  7403. fclose(fp);
  7404. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7405. random_uuid(guid);
  7406. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7407. json_object_put(SignCertificate);
  7408. LWS_Send(message);
  7409. sprintf(tempdata, "SignCertificate,0");
  7410. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7411. {
  7412. result = PASS;
  7413. }
  7414. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7415. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7416. return result;
  7417. }
  7418. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7419. {
  7420. mtrace();
  7421. int result = PASS;
  7422. char message[110]={0};
  7423. char guid[37]={0};
  7424. char tempdata[65]={0};
  7425. json_object *FirmwareStatusNotification = json_object_new_object();
  7426. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7427. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7428. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7429. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7430. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7431. random_uuid(guid);
  7432. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7433. json_object_put(FirmwareStatusNotification);
  7434. LWS_Send(message);
  7435. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7436. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7437. {
  7438. result = PASS;
  7439. }
  7440. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7441. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7442. return result;
  7443. }
  7444. //==========================================
  7445. // send confirm routine
  7446. //==========================================
  7447. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7448. {
  7449. mtrace();
  7450. int result = FAIL;
  7451. char message[100]={0};
  7452. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7453. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7454. LWS_Send(message);
  7455. result = TRUE;
  7456. return result;
  7457. }
  7458. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7459. {
  7460. mtrace();
  7461. int result = FAIL;
  7462. char message[100]={0};
  7463. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7464. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7465. LWS_Send(message);
  7466. result = TRUE;
  7467. return result;
  7468. }
  7469. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7470. {
  7471. mtrace();
  7472. int result = FAIL;
  7473. char message[100]={0};
  7474. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7475. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7476. LWS_Send(message);
  7477. result = TRUE;
  7478. return result;
  7479. }
  7480. int sendClearCacheConfirmation(char *uuid,char *payload)
  7481. {
  7482. mtrace();
  7483. int result = FAIL;
  7484. char message[500]={0};
  7485. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7486. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7487. LWS_Send(message);
  7488. return result;
  7489. }
  7490. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7491. {
  7492. mtrace();
  7493. int result = FAIL;
  7494. char message[500]={0};
  7495. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7496. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7497. LWS_Send(message);
  7498. return result;
  7499. }
  7500. int sendDataTransferConfirmation(char *uuid,char *payload)
  7501. {
  7502. mtrace();
  7503. char statusStr[20]={0};
  7504. char dataStr[10]={0};
  7505. char sstr[20]={0};
  7506. int c = 0;
  7507. char *loc;
  7508. int result = FAIL;
  7509. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7510. /**********************status**************************/
  7511. loc = strstr(payload, "status");
  7512. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7513. c = 0;
  7514. while (loc[3+strlen("status")+c] != '\"')
  7515. {
  7516. sstr[c] = loc[3+strlen("status")+c];
  7517. c++;
  7518. }
  7519. sstr[c] = '\0';
  7520. strcpy(statusStr, sstr);
  7521. /**********************data**************************/
  7522. loc = strstr(payload, "data");
  7523. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7524. c = 0;
  7525. while (loc[3+strlen("data")+c] != '\"')
  7526. {
  7527. sstr[c] = loc[3+strlen("data")+c];
  7528. c++;
  7529. }
  7530. sstr[c] = '\0';
  7531. strcpy(dataStr, sstr);
  7532. return result;
  7533. }
  7534. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7535. {
  7536. mtrace();
  7537. int result = FAIL;
  7538. char message[1000]={0};
  7539. int CompositeScheduleIndex = 0;
  7540. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7541. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7542. if(nPeriod == 0)
  7543. {
  7544. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7545. {
  7546. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7547. ,MESSAGE_TYPE_CALLRESULT
  7548. ,uuid
  7549. ,payload
  7550. ,connectorIdInt);
  7551. }
  7552. else
  7553. {
  7554. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7555. ,MESSAGE_TYPE_CALLRESULT
  7556. ,uuid
  7557. ,payload
  7558. ,connectorIdInt
  7559. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7560. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7561. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7562. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7563. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7564. }
  7565. }
  7566. else
  7567. {
  7568. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7569. ,MESSAGE_TYPE_CALLRESULT
  7570. ,uuid
  7571. ,payload
  7572. ,connectorIdInt
  7573. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7574. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7575. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7576. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7577. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7578. {
  7579. if (idx_sample == 0)
  7580. {
  7581. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7582. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7583. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7584. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7585. }
  7586. else
  7587. {
  7588. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7589. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7590. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7591. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7592. }
  7593. }
  7594. sprintf(message + strlen(message), "]}}]");
  7595. }
  7596. LWS_Send(message);
  7597. result = TRUE;
  7598. return result;
  7599. }
  7600. int sendGetConfigurationConfirmation(char *uuid)
  7601. {
  7602. mtrace();
  7603. int result = FAIL;
  7604. int MaxKeySupported = 0;
  7605. int sentConfigurationNumber= 0;
  7606. int sentunConfigurationNumber= 0;
  7607. char message[1024*10]={0};
  7608. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7609. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7610. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7611. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7612. ,MESSAGE_TYPE_CALLRESULT
  7613. ,uuid );
  7614. //configuration key
  7615. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7616. {
  7617. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7618. {
  7619. if (sentConfigurationNumber == 0)
  7620. {
  7621. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7622. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7623. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7624. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7625. }
  7626. else
  7627. {
  7628. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7629. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7630. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7631. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7632. }
  7633. sentConfigurationNumber = sentConfigurationNumber + 1;
  7634. }
  7635. }
  7636. sprintf(message + strlen(message), "]");
  7637. if(UnknownKeynum != 0)
  7638. {
  7639. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7640. //unkown key
  7641. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7642. {
  7643. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7644. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7645. if(sentunConfigurationNumber == 0)
  7646. {
  7647. sprintf(message + strlen(message), "\"%s\""
  7648. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7649. }
  7650. else
  7651. {
  7652. sprintf(message + strlen(message), ",\"%s\""
  7653. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7654. }
  7655. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7656. }
  7657. sprintf(message + strlen(message), "]");
  7658. }
  7659. sprintf(message + strlen(message), "}]");
  7660. LWS_Send(message);
  7661. return result;
  7662. }
  7663. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7664. {
  7665. mtrace();
  7666. int result = FAIL;
  7667. char message[400]={0};
  7668. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7669. if(strcmp(payload,"")==0)
  7670. {
  7671. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7672. }
  7673. else
  7674. {
  7675. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7676. }
  7677. LWS_Send(message);
  7678. result = TRUE;
  7679. return result;
  7680. }
  7681. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7682. {
  7683. mtrace();
  7684. int result = FAIL;
  7685. char message[80]={0};
  7686. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7687. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7688. LWS_Send(message);
  7689. result = TRUE;
  7690. return result;
  7691. }
  7692. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7693. {
  7694. mtrace();
  7695. int result = FAIL;
  7696. char message[80]={0};
  7697. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7698. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7699. LWS_Send(message);
  7700. result = TRUE;
  7701. return result;
  7702. }
  7703. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7704. {
  7705. mtrace();
  7706. int result = FAIL;
  7707. char message[80]={0};
  7708. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7709. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7710. LWS_Send(message);
  7711. result = TRUE;
  7712. return result;
  7713. }
  7714. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7715. {
  7716. mtrace();
  7717. int result = FAIL;
  7718. char message[80]={0};
  7719. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7720. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7722. LWS_Send(message);
  7723. result = TRUE;
  7724. return result;
  7725. }
  7726. int sendResetConfirmation(char *uuid,char *payload)
  7727. {
  7728. mtrace();
  7729. int result = FAIL;
  7730. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7731. char message[80]={0};
  7732. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7734. LWS_Send(message);
  7735. result = TRUE;
  7736. return result;
  7737. }
  7738. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7739. {
  7740. mtrace();
  7741. int result = FAIL;
  7742. char message[500]={0};
  7743. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7744. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7745. LWS_Send(message);
  7746. result = TRUE;
  7747. return result;
  7748. }
  7749. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7750. {
  7751. mtrace();
  7752. int result = FAIL;
  7753. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7754. char message[80]={0};
  7755. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7756. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7757. LWS_Send(message);
  7758. result = TRUE;
  7759. return result;
  7760. }
  7761. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7762. {
  7763. mtrace();
  7764. int result = FAIL;
  7765. char message[80]={0};
  7766. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7767. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7768. LWS_Send(message);
  7769. result = TRUE;
  7770. return result;
  7771. }
  7772. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7773. {
  7774. mtrace();
  7775. int result = FAIL;
  7776. char message[80]={0};
  7777. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7778. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7779. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7780. LWS_Send(message);
  7781. result = TRUE;
  7782. return result;
  7783. }
  7784. int sendUpdateFirmwareConfirmation(char *uuid)
  7785. {
  7786. mtrace();
  7787. int result = FAIL;
  7788. char message[60]={0};
  7789. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7790. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7791. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7792. LWS_Send(message);
  7793. result = TRUE;
  7794. return result;
  7795. }
  7796. int sendCertificateSignedConfirmation(char *uuid)
  7797. {
  7798. mtrace();
  7799. int result = PASS;
  7800. char message[4096]={0};
  7801. json_object *CertificateSigned = json_object_new_object();
  7802. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7803. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7804. sprintf(message,"[%d,\"%s\",%s]"
  7805. ,MESSAGE_TYPE_CALLRESULT
  7806. ,uuid
  7807. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7808. json_object_put(CertificateSigned);
  7809. LWS_Send(message);
  7810. return result;
  7811. }
  7812. int sendDeleteCertificateConfirmation(char *uuid)
  7813. {
  7814. mtrace();
  7815. int result = PASS;
  7816. char message[4096]={0};
  7817. json_object *DeleteCertificate = json_object_new_object();
  7818. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7819. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7820. sprintf(message,"[%d,\"%s\",%s]"
  7821. ,MESSAGE_TYPE_CALLRESULT
  7822. ,uuid
  7823. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7824. json_object_put(DeleteCertificate);
  7825. LWS_Send(message);
  7826. return result;
  7827. }
  7828. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7829. {
  7830. mtrace();
  7831. int result = PASS;
  7832. char message[4096]={0};
  7833. json_object *ExtendedTriggerMessage = json_object_new_object();
  7834. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7835. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7836. sprintf(message,"[%d,\"%s\",%s]"
  7837. ,MESSAGE_TYPE_CALLRESULT
  7838. ,uuid
  7839. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7840. json_object_put(ExtendedTriggerMessage);
  7841. LWS_Send(message);
  7842. return result;
  7843. }
  7844. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7845. {
  7846. mtrace();
  7847. int result = PASS;
  7848. char message[4096]={0};
  7849. json_object *GetInstalledCertificateIds = json_object_new_object();
  7850. json_object *certificateHashDataDatas = json_object_new_array();
  7851. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7852. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7853. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7854. {
  7855. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7856. {
  7857. json_object *certificateHashData = json_object_new_object();
  7858. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7859. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7860. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7861. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7862. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7863. }
  7864. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7865. }
  7866. else
  7867. {
  7868. json_object_put(certificateHashDataDatas);
  7869. }
  7870. sprintf(message,"[%d,\"%s\",%s]"
  7871. ,MESSAGE_TYPE_CALLRESULT
  7872. ,uuid
  7873. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7874. json_object_put(GetInstalledCertificateIds);
  7875. LWS_Send(message);
  7876. return result;
  7877. }
  7878. int sendGetLogConfirmation(char *uuid)
  7879. {
  7880. mtrace();
  7881. int result = PASS;
  7882. char message[4096]={0};
  7883. json_object *GetLog = json_object_new_object();
  7884. DEBUG_INFO("sendGetLogConfirmation...\n");
  7885. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7886. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7887. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7888. sprintf(message,"[%d,\"%s\",%s]"
  7889. ,MESSAGE_TYPE_CALLRESULT
  7890. ,uuid
  7891. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7892. json_object_put(GetLog);
  7893. LWS_Send(message);
  7894. return result;
  7895. }
  7896. int sendInstallCertificateConfirmation(char *uuid)
  7897. {
  7898. mtrace();
  7899. int result = PASS;
  7900. char message[4096]={0};
  7901. json_object *InstallCertificate = json_object_new_object();
  7902. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7903. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7904. sprintf(message,"[%d,\"%s\",%s]"
  7905. ,MESSAGE_TYPE_CALLRESULT
  7906. ,uuid
  7907. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7908. json_object_put(InstallCertificate);
  7909. LWS_Send(message);
  7910. return result;
  7911. }
  7912. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7913. {
  7914. mtrace();
  7915. int result = PASS;
  7916. char message[4096]={0};
  7917. json_object *SignedUpdateFirmware = json_object_new_object();
  7918. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7919. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7920. sprintf(message,"[%d,\"%s\",%s]"
  7921. ,MESSAGE_TYPE_CALLRESULT
  7922. ,uuid
  7923. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7924. json_object_put(SignedUpdateFirmware);
  7925. LWS_Send(message);
  7926. return result;
  7927. }
  7928. int sendUnknownConfirmation(char *uuid)
  7929. {
  7930. mtrace();
  7931. int result = PASS;
  7932. char message[256]={0};
  7933. DEBUG_INFO("sendUnknownConfirmation...\n");
  7934. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7935. LWS_Send(message);
  7936. return result;
  7937. }
  7938. //==========================================
  7939. // Handle server request routine Start
  7940. //==========================================
  7941. int handleCancelReservationRequest(char *uuid, char *payload)
  7942. {
  7943. mtrace();
  7944. int result = FAIL;
  7945. int gunNO = 0;
  7946. int reservationIdInt = -1;
  7947. char comfirmstr[20];
  7948. DEBUG_INFO("handleCancelReservationRequest...\n");
  7949. json_object *CancelReservation;
  7950. CancelReservation = json_tokener_parse(payload);
  7951. if(!is_error(CancelReservation))
  7952. {
  7953. // Required data
  7954. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7955. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7956. }
  7957. json_object_put(CancelReservation);
  7958. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7959. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7960. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7961. if(reservationIdInt != -1)
  7962. {
  7963. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7964. //check Transaction active
  7965. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7966. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7967. {
  7968. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7969. {
  7970. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7971. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7972. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7973. {
  7974. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7975. }
  7976. else
  7977. {
  7978. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7979. }
  7980. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7981. goto end;
  7982. }
  7983. }
  7984. for (int index = 0; index < CCS_QUANTITY; index++)
  7985. {
  7986. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7987. {
  7988. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7989. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7990. if(gunType[2] == GUN_TYPE_CCS)
  7991. {
  7992. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7993. }
  7994. else
  7995. {
  7996. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7997. }
  7998. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7999. goto end;
  8000. }
  8001. }
  8002. for (int index = 0; index < GB_QUANTITY; index++)
  8003. {
  8004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8005. {
  8006. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8007. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8008. if(gunType[2] == GUN_TYPE_GBT)
  8009. {
  8010. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8011. }
  8012. else
  8013. {
  8014. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8015. }
  8016. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8017. goto end;
  8018. }
  8019. }
  8020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8021. {
  8022. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8023. {
  8024. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8025. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8026. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8027. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8028. goto end;
  8029. }
  8030. }
  8031. for (int index = 0; index < AC_QUANTITY; index++)
  8032. {
  8033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8034. {
  8035. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8036. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8038. {
  8039. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8040. }
  8041. else
  8042. {
  8043. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8044. }
  8045. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8046. goto end;
  8047. }
  8048. }
  8049. }
  8050. //The reservationId does NOT match the reservationId
  8051. sendCancelReservationConfirmation(uuid, comfirmstr);
  8052. end:
  8053. // Fill in ocpp packet uuid
  8054. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8055. return result;
  8056. }
  8057. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8058. {
  8059. mtrace();
  8060. int result = FAIL;
  8061. int gunIndex = -1;
  8062. char typeStr[16]={0};
  8063. char comfirmstr[20];
  8064. int specificId = FALSE;
  8065. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8066. json_object *ChangeAvailability;
  8067. ChangeAvailability = json_tokener_parse(payload);
  8068. if(!is_error(ChangeAvailability))
  8069. {
  8070. // Required data
  8071. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8072. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8073. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8074. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8075. }
  8076. json_object_put(ChangeAvailability);
  8077. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8078. {
  8079. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8080. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8081. }
  8082. else if(gunIndex == 0)
  8083. {
  8084. for(int i=0; i < gunTotalNumber; i++)
  8085. {
  8086. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8087. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8088. }
  8089. }
  8090. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8092. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8093. {
  8094. specificId = TRUE;
  8095. }
  8096. if(specificId == FALSE)
  8097. goto end;
  8098. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8099. {
  8100. //----------------------gunIndex is 0 ------------------------------------------------//
  8101. if(gunIndex == 0)
  8102. {
  8103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8104. {
  8105. for(int i=0; i < gunTotalNumber; i++)
  8106. {
  8107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8108. {
  8109. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8110. {
  8111. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8114. goto end;
  8115. }
  8116. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8118. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8119. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8120. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8121. {
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8123. goto end;
  8124. }
  8125. }
  8126. }//END FOR CHAdeMO_QUANTITY
  8127. for (int index = 0; index < CCS_QUANTITY; index++)
  8128. {
  8129. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8130. {
  8131. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8134. goto end;
  8135. }
  8136. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8143. goto end;
  8144. }
  8145. }
  8146. }//END FOR CCS_QUANTITY
  8147. for (int index = 0; index < GB_QUANTITY; index++)
  8148. {
  8149. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8150. {
  8151. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8152. {
  8153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8154. goto end;
  8155. }
  8156. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8163. goto end;
  8164. }
  8165. }
  8166. }// END FOR GB_QUANTITY
  8167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8168. {
  8169. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8170. {
  8171. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8172. {
  8173. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8174. goto end;
  8175. }
  8176. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8177. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8178. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8181. {
  8182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8183. goto end;
  8184. }
  8185. }
  8186. }// END FOR GENERAL_GUN_QUANTITY
  8187. for (int index = 0; index < AC_QUANTITY; index++)
  8188. {
  8189. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8190. {
  8191. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8192. {
  8193. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8194. goto end;
  8195. }
  8196. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8197. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8198. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8199. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8200. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8201. {
  8202. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8203. goto end;
  8204. }
  8205. }
  8206. }//END FOR AC_QUANTITY
  8207. }// END FOR gunTotalNumber
  8208. }
  8209. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8210. {
  8211. for(int i=0; i < gunTotalNumber; i++)
  8212. {
  8213. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8214. {
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8216. goto end;
  8217. }
  8218. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8219. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8220. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8221. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8222. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8223. {
  8224. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8225. goto end;
  8226. }
  8227. }
  8228. }
  8229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8230. goto end;
  8231. }
  8232. //----------------------gunIndex is not 0 ------------------------------------------------//
  8233. //check Transaction active
  8234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8235. {
  8236. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8237. {
  8238. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8239. {
  8240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8241. goto end;
  8242. }
  8243. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8244. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8245. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8246. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8247. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8248. {
  8249. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8250. goto end;
  8251. }
  8252. else
  8253. {
  8254. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8255. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8256. goto end;
  8257. }
  8258. }
  8259. }//END FOR CHAdeMO_QUANTITY
  8260. for (int index = 0; index < CCS_QUANTITY; index++)
  8261. {
  8262. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8263. {
  8264. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8265. {
  8266. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8267. goto end;
  8268. }
  8269. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8270. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8271. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8272. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8274. {
  8275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8276. goto end;
  8277. }
  8278. else
  8279. {
  8280. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8282. goto end;
  8283. }
  8284. }
  8285. }//END FOR CCS_QUANTITY
  8286. for (int index = 0; index < GB_QUANTITY; index++)
  8287. {
  8288. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8289. {
  8290. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8291. {
  8292. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8293. goto end;
  8294. }
  8295. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8296. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8297. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8298. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8299. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8302. goto end;
  8303. }
  8304. else
  8305. {
  8306. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8307. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8308. goto end;
  8309. }
  8310. }
  8311. }// END FOR GB_QUANTITY
  8312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8313. {
  8314. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8315. {
  8316. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8317. {
  8318. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8319. goto end;
  8320. }
  8321. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8322. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8323. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8324. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8325. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8326. {
  8327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8328. goto end;
  8329. }
  8330. else
  8331. {
  8332. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8333. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8334. goto end;
  8335. }
  8336. }
  8337. }// END FOR GENERAL_GUN_QUANTITY
  8338. for (int index = 0; index < AC_QUANTITY; index++)
  8339. {
  8340. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8341. {
  8342. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8343. {
  8344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8345. goto end;
  8346. }
  8347. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8348. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8349. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8350. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8352. {
  8353. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8354. goto end;
  8355. }
  8356. else
  8357. {
  8358. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8360. goto end;
  8361. }
  8362. }
  8363. }//END FOR AC_QUANTITY
  8364. }//END FOR AvailabilityTypeStr[Inoperative]
  8365. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8366. {
  8367. //----------------------gunIndex is 0 ------------------------------------------------//
  8368. if(gunIndex == 0)
  8369. {
  8370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8371. {
  8372. for(int i=0; i < gunTotalNumber; i++)
  8373. {
  8374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8375. {
  8376. 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
  8377. {
  8378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8379. goto end;
  8380. }
  8381. }//END FOR CHAdeMO_QUANTITY
  8382. for (int index = 0; index < CCS_QUANTITY; index++)
  8383. {
  8384. 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
  8385. {
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8387. goto end;
  8388. }
  8389. }//END FOR CCS_QUANTITY
  8390. for (int index = 0; index < GB_QUANTITY; index++)
  8391. {
  8392. 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
  8393. {
  8394. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8396. goto end;
  8397. }
  8398. }// END FOR GB_QUANTITY
  8399. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8400. {
  8401. 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
  8402. {
  8403. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8405. goto end;
  8406. }
  8407. }// END FOR GENERAL_GUN_QUANTITY
  8408. for (int index = 0; index < AC_QUANTITY; index++)
  8409. {
  8410. 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
  8411. {
  8412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8413. goto end;
  8414. }
  8415. }//END FOR CHAdeMO_QUANTITY
  8416. }// END FOR gunTotalNumber
  8417. }
  8418. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8419. {
  8420. for(int i=0; i < gunTotalNumber; i++)
  8421. {
  8422. for (int index = 0; index < AC_QUANTITY; index++)
  8423. {
  8424. 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
  8425. {
  8426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8427. goto end;
  8428. }
  8429. }//END FOR CHAdeMO_QUANTITY
  8430. } // END FOR gunTotalNumber
  8431. }
  8432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8433. goto end;
  8434. }
  8435. //----------------------gunIndex is not 0 ------------------------------------------------//
  8436. //check Transaction active
  8437. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8438. {
  8439. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8440. {
  8441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8442. goto end;
  8443. }
  8444. }//END FOR CHAdeMO_QUANTITY
  8445. for (int index = 0; index < CCS_QUANTITY; index++)
  8446. {
  8447. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8448. {
  8449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8450. goto end;
  8451. }
  8452. }//END FOR CCS_QUANTITY
  8453. for (int index = 0; index < GB_QUANTITY; index++)
  8454. {
  8455. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8456. {
  8457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8458. goto end;
  8459. }
  8460. }// END FOR GB_QUANTITY
  8461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8462. {
  8463. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8464. {
  8465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8466. goto end;
  8467. }
  8468. }// END FOR GENERAL_GUN_QUANTITY
  8469. for (int index = 0; index < AC_QUANTITY; index++)
  8470. {
  8471. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8472. {
  8473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8474. goto end;
  8475. }
  8476. }//END FOR AC_QUANTITY
  8477. }//END FOR AvailabilityTypeStr[Operative]
  8478. end:
  8479. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8480. {
  8481. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8482. }
  8483. else
  8484. {
  8485. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8486. }
  8487. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8488. {
  8489. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8490. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8491. }
  8492. else if(gunIndex == 0)
  8493. {
  8494. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8495. {
  8496. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8497. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8498. }
  8499. }
  8500. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8501. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8502. return result;
  8503. }
  8504. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8505. {
  8506. mtrace();
  8507. int valueInvalid = NO;
  8508. int result = FAIL;
  8509. char keystr[40]={0};
  8510. char valuestr[501]={0}; //value should be limited in 500 bytes
  8511. char comfirmstr[20]={0};
  8512. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8513. json_object *ChangeConfiguration;
  8514. ChangeConfiguration = json_tokener_parse(payload);
  8515. if(!is_error(ChangeConfiguration))
  8516. {
  8517. // Required data
  8518. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8519. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8520. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8521. {
  8522. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8523. }
  8524. else
  8525. {
  8526. valueInvalid = YES;
  8527. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8528. }
  8529. }
  8530. json_object_put(ChangeConfiguration);
  8531. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8532. {
  8533. DEBUG_ERROR("Payload is null or not accepted.\n");
  8534. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8535. }
  8536. else
  8537. {
  8538. int status = setKeyValue(keystr, valuestr);
  8539. switch(status)
  8540. {
  8541. case ConfigurationStatus_Accepted:
  8542. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8543. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8544. StoreConfigurationTable();
  8545. break;
  8546. case RebootRequired:
  8547. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8548. StoreConfigurationTable();
  8549. break;
  8550. case NotSupported:
  8551. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8552. break;
  8553. case ConfigurationStatus_Rejected:
  8554. default:
  8555. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8556. break;
  8557. }
  8558. }
  8559. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8560. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8561. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8562. {
  8563. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8564. SetOcppConnStatus(FALSE);
  8565. }
  8566. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8567. {
  8568. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8569. }
  8570. return result;
  8571. }
  8572. int handleClearCacheRequest(char *uuid, char *payload)
  8573. {
  8574. mtrace();
  8575. int result = FAIL;
  8576. char comfirmstr[20];
  8577. char rmFileCmd[100]={0};
  8578. struct stat stats;
  8579. DEBUG_INFO("handleClearCacheRequest...\n");
  8580. stat("/Storage/OCPP_PH", &stats);
  8581. // Check for directory existence
  8582. if (S_ISDIR(stats.st_mode) == 1)
  8583. {}
  8584. else
  8585. {
  8586. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8587. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8588. system(rmFileCmd);
  8589. }
  8590. if(OCPP_cleanLocalCache())
  8591. {
  8592. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8593. }
  8594. else
  8595. {
  8596. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8597. }
  8598. sendClearCacheConfirmation(uuid, comfirmstr);
  8599. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8600. return result;
  8601. }
  8602. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8603. {
  8604. mtrace();
  8605. int result = FAIL;
  8606. int resultRename;
  8607. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8608. char chargingProfilePurposeStr[26]={0};
  8609. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8610. char tempchargingProfilePurposeStr[26]={0};
  8611. char str[100]={0};
  8612. char fname[200]={0};
  8613. char comfirmstr[20]={0};
  8614. char word[1600]={0};
  8615. int clearflag = FALSE;
  8616. int chargingProfileIdIsNULL = FALSE;
  8617. int connectorIsNULL = FALSE;
  8618. int chargingProfilePurposeIsNULL = FALSE;
  8619. int stackLevelIsNULL = FALSE;
  8620. //int GotoEnd = FALSE;
  8621. FILE *fptr1, *fptr2;
  8622. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8623. int n_chargingProfile=0;
  8624. int isEmptyFile = FALSE;
  8625. char sLineWord[1600]={0};
  8626. char chargingProfiles[10][100]={0};
  8627. int ChargeProfileCount = 0;
  8628. int ch;
  8629. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8630. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8631. json_object *ClearChargingProfile;
  8632. ClearChargingProfile = json_tokener_parse(payload);
  8633. if(!is_error(ClearChargingProfile))
  8634. {
  8635. // Optional data
  8636. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8637. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8638. else
  8639. chargingProfileIdIsNULL = TRUE;
  8640. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8641. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8642. else
  8643. connectorIsNULL = TRUE;
  8644. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8645. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8646. else
  8647. chargingProfilePurposeIsNULL = TRUE;
  8648. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8649. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8650. else
  8651. stackLevelIsNULL = TRUE;
  8652. }
  8653. json_object_put(ClearChargingProfile);
  8654. if(connectorIsNULL == FALSE)
  8655. {
  8656. switch(connectorIdInt)
  8657. {
  8658. case 0:
  8659. if(chargingProfilePurposeIsNULL == TRUE)
  8660. {
  8661. int l = 0;
  8662. strcpy(fname, ChargePointMaxProfile_JSON);
  8663. if((access(fname,F_OK))!=-1)
  8664. {
  8665. strcpy(chargingProfiles[l], fname);
  8666. l = l + 1;
  8667. }
  8668. strcpy(fname, TxDefaultProfile_0_JSON);
  8669. if((access(fname,F_OK))!=-1)
  8670. {
  8671. strcpy(chargingProfiles[l], fname);
  8672. l = l + 1;
  8673. }
  8674. ChargeProfileCount = l;
  8675. }
  8676. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8677. {
  8678. strcpy(fname, ChargePointMaxProfile_JSON);
  8679. if((access(fname,F_OK))!=-1)
  8680. {
  8681. strcpy(chargingProfiles[0], fname);
  8682. ChargeProfileCount = 1;
  8683. }
  8684. }
  8685. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8686. {
  8687. strcpy(fname, TxDefaultProfile_0_JSON);
  8688. if((access(fname,F_OK))!=-1)
  8689. {
  8690. strcpy(chargingProfiles[0], fname);
  8691. ChargeProfileCount = 1;
  8692. }
  8693. }
  8694. break;
  8695. default:
  8696. if(chargingProfilePurposeIsNULL == TRUE)
  8697. {
  8698. int m = 0;
  8699. memset(fname, 0, ARRAY_SIZE(fname));
  8700. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8701. if((access(fname,F_OK))!=-1)
  8702. {
  8703. strcpy(chargingProfiles[m], fname);
  8704. m = m + 1;
  8705. }
  8706. memset(fname, 0, ARRAY_SIZE(fname));
  8707. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8708. if((access(fname,F_OK))!=-1)
  8709. {
  8710. strcpy(chargingProfiles[m], fname);
  8711. m = m + 1;
  8712. }
  8713. ChargeProfileCount = m;
  8714. }
  8715. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8716. {
  8717. //strcpy(fname, TxDefaultProfile_1_JSON);
  8718. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8719. if((access(fname,F_OK))!=-1)
  8720. {
  8721. strcpy(chargingProfiles[0], fname);
  8722. ChargeProfileCount = 1;
  8723. }
  8724. }
  8725. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8726. {
  8727. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8728. if((access(fname,F_OK))!=-1)
  8729. {
  8730. strcpy(chargingProfiles[0], fname);
  8731. ChargeProfileCount = 1;
  8732. }
  8733. //strcpy(fname, TxProfile_1_JSON);
  8734. }
  8735. //strcpy(fname, ChargePointMaxProfile_JSON );
  8736. break;
  8737. }
  8738. }
  8739. else // Check all Charging Profiles
  8740. {
  8741. int i = 0;
  8742. char fnametemp[200]={0};
  8743. ChargeProfileCount = 0;
  8744. //Check ChargePointMaxProfile.json exit
  8745. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8746. {
  8747. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8748. i = i + 1;
  8749. }
  8750. //Check TxDefaultProfile_0.json exit
  8751. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8752. {
  8753. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8754. i = i + 1;
  8755. }
  8756. //Check TxDefaultProfile_%d.json
  8757. for(int j=1; j <= gunTotalNumber; j++)
  8758. {
  8759. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8760. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8761. if((access(fnametemp,F_OK))!=-1)
  8762. {
  8763. strcpy(chargingProfiles[i], fnametemp);
  8764. i = i + 1;
  8765. }
  8766. }
  8767. //Check TxProfile_%d.json
  8768. for(int j=1; j <= gunTotalNumber; j++)
  8769. {
  8770. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8771. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8772. if((access(fnametemp,F_OK))!=-1)
  8773. {
  8774. strcpy(chargingProfiles[i], fnametemp);
  8775. i = i + 1;
  8776. }
  8777. }
  8778. ChargeProfileCount = i;
  8779. }// End connectorIsNULL is TRUE
  8780. if(ChargeProfileCount == 0)
  8781. {
  8782. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8783. goto end;
  8784. }
  8785. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8786. {
  8787. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8788. goto end;
  8789. }
  8790. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8791. {
  8792. memset(str, 0, ARRAY_SIZE(str));
  8793. // clear temp file
  8794. sprintf(str,"rm -f %s",temp);
  8795. system(str);
  8796. for(int k=0; k < ChargeProfileCount; k++)
  8797. {
  8798. memset(str, 0, ARRAY_SIZE(str));
  8799. //clear file in C
  8800. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8801. system(str);
  8802. }
  8803. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8804. goto end;
  8805. }
  8806. else if(connectorIsNULL == TRUE)
  8807. {
  8808. for(int k=0; k < ChargeProfileCount; k++)
  8809. {
  8810. fptr1 = fopen(chargingProfiles[k], "r");
  8811. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8812. //Check Charging Profile Count
  8813. while(fscanf(fptr1, "%s", word) != EOF)
  8814. {
  8815. //DEBUG_INFO("word=%s\n",word);
  8816. if(strstr(word, "chargingProfileId")!= NULL)
  8817. {
  8818. //DEBUG_INFO("test chargingProfileId \n");
  8819. n_chargingProfile = n_chargingProfile + 1;
  8820. //DEBUG_INFO("chargingProfileId Found\n");
  8821. }
  8822. }
  8823. rewind(fptr1);
  8824. //search Charging Profile Element
  8825. //int i= 0;
  8826. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8827. {
  8828. json_object *tmpProfilee;
  8829. tmpProfilee = json_tokener_parse(sLineWord);
  8830. if(!is_error(tmpProfilee))
  8831. {
  8832. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8833. {
  8834. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8835. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8836. }
  8837. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8838. {
  8839. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8840. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8841. }
  8842. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8843. {
  8844. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8845. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8846. }
  8847. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8848. {
  8849. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8850. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8851. }
  8852. }
  8853. json_object_put(tmpProfilee);
  8854. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8855. {
  8856. //------- not write to fptr2-------//
  8857. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8858. //clearflag = TRUE;
  8859. }
  8860. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8861. {
  8862. //------- not write to fptr2-------//
  8863. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8864. }
  8865. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8866. {
  8867. //------- not write to fptr2-------//
  8868. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8869. }
  8870. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8871. {
  8872. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8873. }
  8874. else
  8875. {
  8876. fprintf(fptr2, sLineWord);//writing data into file
  8877. }
  8878. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8879. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8880. if(clearflag == TRUE)
  8881. {
  8882. fclose(fptr1);
  8883. fclose(fptr2);
  8884. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8885. system(str);
  8886. // clear temp file
  8887. sprintf(str,"rm -f %s",temp);
  8888. system(str);
  8889. }
  8890. else
  8891. {
  8892. fclose(fptr1);
  8893. fclose(fptr2);
  8894. memset(str, 0, ARRAY_SIZE(str));
  8895. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8896. system(str);
  8897. resultRename = rename(temp, chargingProfiles[k]);
  8898. if(resultRename == 0)
  8899. {
  8900. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8901. }
  8902. else
  8903. {
  8904. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8905. }
  8906. if(comfirmstr[0]== 0)
  8907. {
  8908. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8909. }
  8910. //Check chargingProfile is empty file
  8911. /*------ Read the file ----------------*/
  8912. fptr1=fopen(chargingProfiles[k],"r");
  8913. ch=fgetc(fptr1);
  8914. rewind(fptr1);
  8915. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8916. if(ch!=EOF)
  8917. {
  8918. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8919. {
  8920. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8921. if(sLineWord[0]=='\0')
  8922. {
  8923. isEmptyFile = TRUE;
  8924. break;
  8925. }
  8926. else
  8927. {
  8928. isEmptyFile = FALSE;
  8929. break;
  8930. }
  8931. }
  8932. }
  8933. else
  8934. isEmptyFile = TRUE;
  8935. fclose(fptr1);
  8936. if(isEmptyFile == TRUE)
  8937. {
  8938. memset(str, 0, ARRAY_SIZE(str));
  8939. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8940. system(str);
  8941. }
  8942. }
  8943. }// End of while(int k=0; k < ChargePointCount; k++)
  8944. }
  8945. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8946. {
  8947. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8948. for(int k=0; k < ChargeProfileCount; k++)
  8949. {
  8950. fptr1 = fopen(chargingProfiles[k], "r");
  8951. fptr2 = fopen(temp, "w+");
  8952. //Check Charging Profile Count
  8953. while(fscanf(fptr1, "%s", word) != EOF)
  8954. {
  8955. //DEBUG_INFO("word=%s\n",word);
  8956. if(strstr(word, "chargingProfileId")!= NULL)
  8957. {
  8958. n_chargingProfile = n_chargingProfile + 1;
  8959. }
  8960. }
  8961. rewind(fptr1);
  8962. //search Charging Profile Element
  8963. //int i= 0;
  8964. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8965. {
  8966. json_object *tmpProfilee;
  8967. tmpProfilee = json_tokener_parse(sLineWord);
  8968. if(!is_error(tmpProfilee))
  8969. {
  8970. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8971. {
  8972. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8973. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8974. }
  8975. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8976. {
  8977. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8978. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8979. }
  8980. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8981. {
  8982. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8983. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8984. }
  8985. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8986. {
  8987. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8988. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8989. }
  8990. }
  8991. json_object_put(tmpProfilee);
  8992. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8993. {
  8994. //------- not write to fptr2-------//
  8995. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8996. //clearflag = TRUE;
  8997. }
  8998. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8999. {
  9000. //------- not write to fptr2-------//
  9001. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9002. }
  9003. else if(stackLevelIsNULL == TRUE)
  9004. {
  9005. //Clear Whole File
  9006. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9007. clearflag = TRUE;
  9008. break;
  9009. }
  9010. else
  9011. {
  9012. fprintf(fptr2, sLineWord);//writing data into file
  9013. }
  9014. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9015. }
  9016. if(clearflag == TRUE)
  9017. {
  9018. fclose(fptr1);
  9019. fclose(fptr2);
  9020. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9021. system(str);
  9022. // clear temp file
  9023. sprintf(str,"rm -f %s",temp);
  9024. system(str);
  9025. }
  9026. else
  9027. {
  9028. fclose(fptr1);
  9029. fclose(fptr2);
  9030. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9031. system(str);
  9032. resultRename = rename(temp, chargingProfiles[k]);
  9033. if(resultRename == 0)
  9034. {
  9035. DEBUG_INFO("File ChargingProfile renamed successfully");
  9036. }
  9037. else
  9038. {
  9039. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9040. }
  9041. if(comfirmstr[0]== 0)
  9042. {
  9043. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9044. }
  9045. //Check chargingProfile is empty file
  9046. /*------ Read the file ----------------*/
  9047. fptr1=fopen(chargingProfiles[k],"r");
  9048. ch=fgetc(fptr1);
  9049. rewind(fptr1);
  9050. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9051. if(ch!=EOF)
  9052. {
  9053. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9054. {
  9055. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9056. if(sLineWord[0]=='\0')
  9057. {
  9058. isEmptyFile = TRUE;
  9059. break;
  9060. }
  9061. else
  9062. {
  9063. isEmptyFile = FALSE;
  9064. break;
  9065. }
  9066. }
  9067. }
  9068. else
  9069. isEmptyFile = TRUE;
  9070. fclose(fptr1);
  9071. if(isEmptyFile == TRUE)
  9072. {
  9073. memset(str, 0, ARRAY_SIZE(str));
  9074. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9075. system(str);
  9076. }
  9077. /*------- End of reading ---------------*/
  9078. }
  9079. } // while(int k=0; k < ChargeProfileCount; k++)
  9080. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9081. end:
  9082. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9083. {
  9084. if(connectorIdInt == 0)
  9085. {
  9086. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9087. {
  9088. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9089. }
  9090. }
  9091. else
  9092. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9093. }
  9094. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9095. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9096. return result;
  9097. }
  9098. void createFirmwareVersionByDataTransfer(void)
  9099. {
  9100. json_object *FirmwareDataTransfer = json_object_new_object();
  9101. // AC & DC model
  9102. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9103. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9104. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9105. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9106. // DC model
  9107. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9108. {
  9109. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9110. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9111. (gunType[3] != GUN_TYPE_UNKNOWN))
  9112. {
  9113. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9114. }
  9115. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9116. {
  9117. // DS DM DW
  9118. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9119. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9120. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9121. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9122. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9123. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9124. }
  9125. else
  9126. {
  9127. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9128. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9129. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9130. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9131. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9132. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9133. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9134. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9135. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9136. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9137. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9138. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9139. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9140. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9141. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9142. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9143. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9144. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9145. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9146. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9147. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9148. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9149. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9150. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9151. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9152. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9153. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9154. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9155. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9156. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9157. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9158. }
  9159. }
  9160. // 4G model
  9161. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9162. {
  9163. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9164. }
  9165. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9166. json_object_put(FirmwareDataTransfer);
  9167. }
  9168. int handleDataTransferRequest(char *uuid, char *payload)
  9169. {
  9170. mtrace();
  9171. json_object *response = json_object_new_object();
  9172. int result = FAIL;
  9173. char tempvendorId[255]={0};
  9174. char tempmessageId[50]={0};
  9175. char tempdata[1024]={0};
  9176. char message[2048]={0};
  9177. DEBUG_INFO("handleDataTransferRequest...\n");
  9178. if((uuid != NULL) && (payload != NULL))
  9179. {
  9180. json_object *DataTransfer;
  9181. DataTransfer = json_tokener_parse(payload);
  9182. if(!is_error(DataTransfer))
  9183. {
  9184. // Required data
  9185. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9186. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9187. // Optional data
  9188. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9189. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9190. if(json_object_object_get(DataTransfer, "data") != NULL)
  9191. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9192. result = PASS;
  9193. }
  9194. json_object_put(DataTransfer);
  9195. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9196. {
  9197. // Send all moudle firmware version on EVSE
  9198. createFirmwareVersionByDataTransfer();
  9199. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9200. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9201. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9202. json_object_put(response);
  9203. }
  9204. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9205. {
  9206. system("/usr/bin/run_tmate_restart.sh &");
  9207. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9208. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9209. json_object_put(response);
  9210. }
  9211. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9212. {
  9213. json_object *data;
  9214. data = json_tokener_parse(tempdata);
  9215. if(!is_error(data))
  9216. {
  9217. 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))
  9218. {
  9219. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9220. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9221. if(json_object_object_get(data, "SOC") != NULL)
  9222. {
  9223. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9224. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9225. }
  9226. if(json_object_object_get(data, "Energy") != NULL)
  9227. {
  9228. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9229. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9230. }
  9231. if(json_object_object_get(data, "Duration") != NULL)
  9232. {
  9233. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9234. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9235. }
  9236. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9237. }
  9238. else
  9239. {
  9240. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9241. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9242. }
  9243. }
  9244. else
  9245. {
  9246. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9247. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9248. }
  9249. json_object_put(data);
  9250. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9251. json_object_put(response);
  9252. }
  9253. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9254. {
  9255. json_object *data;
  9256. data = json_tokener_parse(tempdata);
  9257. if(!is_error(data))
  9258. {
  9259. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9260. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9261. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9262. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9263. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9264. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9265. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9266. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9267. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9268. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9269. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9270. }
  9271. else
  9272. {
  9273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9275. }
  9276. json_object_put(data);
  9277. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9278. json_object_put(response);
  9279. }
  9280. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9281. {
  9282. json_object *data;
  9283. data = json_tokener_parse(tempdata);
  9284. if(!is_error(data))
  9285. {
  9286. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9287. if(json_object_object_get(data, "idToken") != NULL)
  9288. {
  9289. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9290. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9291. }
  9292. if(json_object_object_get(data, "price") != NULL)
  9293. {
  9294. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9295. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9296. }
  9297. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9298. }
  9299. else
  9300. {
  9301. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9302. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9303. }
  9304. json_object_put(data);
  9305. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9306. json_object_put(response);
  9307. }
  9308. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9309. {
  9310. json_object *data;
  9311. data = json_tokener_parse(tempdata);
  9312. if(!is_error(data))
  9313. {
  9314. if(json_object_object_get(data, "txId") != NULL)
  9315. {
  9316. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9317. for(int idx = 0;idx<gunTotalNumber;idx++)
  9318. {
  9319. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9320. {
  9321. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9322. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9323. if(json_object_object_get(data, "description") != NULL)
  9324. {
  9325. // California pricing V1.0
  9326. DEBUG_INFO("California pricing V1.0\n");
  9327. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9328. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9329. }
  9330. else
  9331. {
  9332. // California pricing V1.1
  9333. DEBUG_INFO("California pricing V1.1\n");
  9334. if(json_object_object_get(data, "timestamp") != NULL)
  9335. {
  9336. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9337. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9338. }
  9339. if(json_object_object_get(data, "meterValue") != NULL)
  9340. {
  9341. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9342. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9343. }
  9344. if(json_object_object_get(data, "cost") != NULL)
  9345. {
  9346. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9347. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9348. }
  9349. if(json_object_object_get(data, "state") != NULL)
  9350. {
  9351. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9352. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9353. }
  9354. if(json_object_object_get(data, "chargingPrice") != NULL)
  9355. {
  9356. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9357. {
  9358. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9359. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9360. }
  9361. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9362. {
  9363. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9364. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9365. }
  9366. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9367. {
  9368. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9369. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9370. }
  9371. }
  9372. if(json_object_object_get(data, "idlePrice") != NULL)
  9373. {
  9374. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9375. {
  9376. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9377. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9378. }
  9379. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9380. {
  9381. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9382. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9383. }
  9384. }
  9385. if(json_object_object_get(data, "nextPeriod") != NULL)
  9386. {
  9387. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9388. {
  9389. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9390. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9391. }
  9392. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9393. {
  9394. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9395. {
  9396. 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")));
  9397. 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"));
  9398. }
  9399. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9400. {
  9401. 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")));
  9402. 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"));
  9403. }
  9404. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9405. {
  9406. 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")));
  9407. 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"));
  9408. }
  9409. }
  9410. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9411. {
  9412. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9413. {
  9414. 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")));
  9415. 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"));
  9416. }
  9417. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9418. {
  9419. 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")));
  9420. 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"));
  9421. }
  9422. }
  9423. }
  9424. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9425. {
  9426. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9427. {
  9428. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9429. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9430. }
  9431. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9432. {
  9433. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9434. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9435. }
  9436. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9437. {
  9438. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9439. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9440. }
  9441. }
  9442. }
  9443. }
  9444. }
  9445. }
  9446. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9447. }
  9448. else
  9449. {
  9450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9451. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9452. }
  9453. json_object_put(data);
  9454. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9455. json_object_put(response);
  9456. }
  9457. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9458. {
  9459. json_object *data;
  9460. data = json_tokener_parse(tempdata);
  9461. if(!is_error(data))
  9462. {
  9463. if(json_object_object_get(data, "txId") != NULL)
  9464. {
  9465. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9466. for(int idx = 0;idx<gunTotalNumber;idx++)
  9467. {
  9468. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9469. {
  9470. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9471. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9472. if(json_object_object_get(data, "description") != NULL)
  9473. {
  9474. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9475. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9476. }
  9477. }
  9478. }
  9479. }
  9480. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9481. }
  9482. else
  9483. {
  9484. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9485. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9486. }
  9487. json_object_put(data);
  9488. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9489. json_object_put(response);
  9490. }
  9491. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9492. {
  9493. json_object *data;
  9494. data = json_tokener_parse(tempdata);
  9495. if(!is_error(data))
  9496. {
  9497. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9498. if(json_object_object_get(data, "Content_Type") != NULL)
  9499. {
  9500. 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))
  9501. {
  9502. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9503. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9504. {
  9505. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9506. }
  9507. }
  9508. else
  9509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9510. }
  9511. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9512. }
  9513. else
  9514. {
  9515. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9516. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9517. }
  9518. json_object_put(data);
  9519. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9520. json_object_put(response);
  9521. }
  9522. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9523. {
  9524. json_object *data;
  9525. data = json_tokener_parse(tempdata);
  9526. if(!is_error(data))
  9527. {
  9528. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9529. if(json_object_object_get(data, "ConnectorId") != NULL)
  9530. {
  9531. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9532. }
  9533. if(json_object_object_get(data, "SerialNo") != NULL)
  9534. {
  9535. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9536. }
  9537. if(json_object_object_get(data, "Page_Index") != NULL)
  9538. {
  9539. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9540. }
  9541. if(json_object_object_get(data, "Duration") != NULL)
  9542. {
  9543. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9544. }
  9545. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9546. }
  9547. else
  9548. {
  9549. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9550. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9551. }
  9552. json_object_put(data);
  9553. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9554. json_object_put(response);
  9555. }
  9556. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9557. {
  9558. json_object *data;
  9559. data = json_tokener_parse(tempdata);
  9560. if(!is_error(data))
  9561. {
  9562. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9563. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9564. {
  9565. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9566. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9567. else
  9568. {
  9569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9570. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9571. }
  9572. }
  9573. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9574. {
  9575. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9576. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9577. else
  9578. {
  9579. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9580. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9581. }
  9582. }
  9583. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9584. {
  9585. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9586. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9587. else
  9588. {
  9589. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9590. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9591. }
  9592. }
  9593. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9594. {
  9595. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9596. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9597. else
  9598. {
  9599. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9600. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9601. }
  9602. }
  9603. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9604. {
  9605. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9606. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9607. else
  9608. {
  9609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9610. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9611. }
  9612. }
  9613. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9614. {
  9615. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9616. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9617. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9618. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9619. else
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9623. }
  9624. }
  9625. if(json_object_object_get(data, "isAuthentication") != NULL)
  9626. {
  9627. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9628. {
  9629. case 0:
  9630. case 1:
  9631. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9632. break;
  9633. default:
  9634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9635. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9636. break;
  9637. }
  9638. }
  9639. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9640. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9641. }
  9642. else
  9643. {
  9644. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9645. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9646. }
  9647. json_object_put(data);
  9648. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9649. json_object_put(response);
  9650. }
  9651. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9652. {
  9653. json_object *data;
  9654. data = json_tokener_parse(tempdata);
  9655. if(!is_error(data))
  9656. {
  9657. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9658. if(json_object_object_get(data, "stationName") != NULL)
  9659. {
  9660. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9661. }
  9662. else
  9663. {
  9664. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9665. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9666. }
  9667. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9668. {
  9669. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9670. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9671. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9672. }
  9673. }
  9674. else
  9675. {
  9676. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9677. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9678. }
  9679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9680. json_object_put(response);
  9681. }
  9682. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9683. {
  9684. json_object *data;
  9685. data = json_tokener_parse(tempdata);
  9686. if(!is_error(data))
  9687. {
  9688. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9689. if(json_object_object_get(data, "weatherId") != NULL)
  9690. {
  9691. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9692. }
  9693. else
  9694. {
  9695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9696. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9697. }
  9698. if(json_object_object_get(data, "Temperature") != NULL)
  9699. {
  9700. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9701. }
  9702. else
  9703. {
  9704. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9705. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9706. }
  9707. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9708. {
  9709. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9710. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9711. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9712. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9713. }
  9714. }
  9715. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9716. {
  9717. json_object *data;
  9718. data = json_tokener_parse(tempdata);
  9719. if(!is_error(data))
  9720. {
  9721. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9722. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9723. {
  9724. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9725. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9726. }
  9727. else
  9728. {
  9729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9730. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9731. }
  9732. }
  9733. else
  9734. {
  9735. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9736. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9737. }
  9738. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9739. json_object_put(response);
  9740. }
  9741. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9742. {
  9743. json_object *data;
  9744. data = json_tokener_parse(tempdata);
  9745. if(!is_error(data))
  9746. {
  9747. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9748. {
  9749. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9750. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9751. if(gun_index < gunTotalNumber)
  9752. {
  9753. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9754. {
  9755. json_object *responsedata = json_object_new_object();
  9756. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9757. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9758. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9759. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9760. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9761. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9762. }
  9763. else
  9764. {
  9765. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9766. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9767. }
  9768. }
  9769. else
  9770. {
  9771. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9772. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9773. }
  9774. }
  9775. else
  9776. {
  9777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9778. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9779. }
  9780. }
  9781. else
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9784. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9785. }
  9786. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9787. json_object_put(response);
  9788. }
  9789. else
  9790. {
  9791. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9792. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9793. }
  9794. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9795. json_object_put(response);
  9796. }
  9797. else
  9798. {
  9799. // Can not find valid message id
  9800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9801. }
  9802. }
  9803. else
  9804. {
  9805. // Payload is null
  9806. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9807. }
  9808. LWS_Send(message);
  9809. return result;
  9810. }
  9811. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9812. {
  9813. mtrace();
  9814. int result = FAIL;
  9815. int connectorIdInt, durationInt;
  9816. char chargingRateUnitStr[4]={0};
  9817. char comfirmstr[20];
  9818. int confirmPeriods = 0;
  9819. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9820. json_object *GetCompositeSchedule;
  9821. GetCompositeSchedule = json_tokener_parse(payload);
  9822. if(!is_error(GetCompositeSchedule))
  9823. {
  9824. // Required data
  9825. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9826. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9827. else
  9828. connectorIdInt = -1;
  9829. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9830. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9831. else
  9832. durationInt = 86400;
  9833. // Optional data
  9834. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9835. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9836. }
  9837. json_object_put(GetCompositeSchedule);
  9838. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9839. if((connectorIdInt == 0) ||
  9840. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9841. {
  9842. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9843. struct StructChargingProfile tmpProfile[1];
  9844. if(strstr(chargingRateUnitStr, "W") != NULL)
  9845. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9846. else
  9847. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9848. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9849. {
  9850. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9851. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9852. }
  9853. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9854. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9855. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9856. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9857. {
  9858. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9859. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9860. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9861. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9862. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9863. {
  9864. confirmPeriods = idx;
  9865. break;
  9866. }
  9867. }
  9868. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9869. {
  9870. confirmPeriods += 1;
  9871. }
  9872. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9873. }
  9874. else
  9875. {
  9876. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9877. }
  9878. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9879. return result;
  9880. }
  9881. int handleGetConfigurationRequest(char *uuid, char *payload)
  9882. {
  9883. mtrace();
  9884. int result = FAIL;
  9885. int MaxKeySupported = 0;
  9886. int n_keys = 0;
  9887. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9888. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9889. json_object *GetConfiguration;
  9890. GetConfiguration = json_tokener_parse(payload);
  9891. if(!is_error(GetConfiguration))
  9892. {
  9893. // Optional data
  9894. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9895. {
  9896. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9897. {
  9898. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9899. n_keys = idx + 1;
  9900. }
  9901. }
  9902. }
  9903. json_object_put(GetConfiguration);
  9904. UnknownKeynum = 0;
  9905. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9906. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9907. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9908. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9909. if(n_keys != 0)
  9910. {
  9911. for(int i=0;i<n_keys;i++)
  9912. {
  9913. getKeyValue(requestKey[i]);
  9914. }
  9915. }
  9916. else
  9917. {
  9918. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9919. getKeyValue("");
  9920. }
  9921. processUnkownKey();
  9922. sendGetConfigurationConfirmation(uuid);
  9923. return result;
  9924. }
  9925. static char fnamePlusPath[100]={0};
  9926. static char fnamePWithNoPath[60]={0};
  9927. void checkUploadLog(void)
  9928. {
  9929. FILE *fp;
  9930. /* Open the command for reading. */
  9931. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9932. if (fp == NULL) {
  9933. DEBUG_WARN("Failed to run command\n" );
  9934. exit(1);
  9935. }
  9936. int ftppathlen = 0;
  9937. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9938. int i = 0;
  9939. /* Read the output a line at a time - output it. */
  9940. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9941. if(i==0)
  9942. {
  9943. ftppathlen = strlen(fnamePlusPath);
  9944. DEBUG_INFO("%s\n", fnamePlusPath);
  9945. fnamePlusPath[ftppathlen]='\0';
  9946. break;
  9947. }
  9948. i= i+1;
  9949. }
  9950. /* close */
  9951. pclose(fp);
  9952. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9953. {
  9954. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9955. {
  9956. fnamePlusPath[k]='\0';
  9957. }
  9958. }
  9959. i=1;
  9960. //char fname[60]={0};
  9961. while(i < ftppathlen)
  9962. {
  9963. int len=ftppathlen-i;
  9964. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9965. {
  9966. DEBUG_INFO("compare '/' all right\n");
  9967. break;
  9968. }
  9969. i=i+1;
  9970. }
  9971. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9972. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9973. fnamePWithNoPath[i+1] = '\0';
  9974. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9975. {
  9976. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9977. {
  9978. fnamePWithNoPath[j]='\0';
  9979. }
  9980. }
  9981. FILE* fp1 = fopen(fnamePlusPath, "r");
  9982. if (fp1)
  9983. {
  9984. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9985. // file exists
  9986. fclose(fp1);
  9987. }
  9988. else
  9989. {
  9990. // file doesn't exist
  9991. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9992. }
  9993. }
  9994. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9995. {
  9996. mtrace();
  9997. int result = FAIL;
  9998. time_t CurrentTime;
  9999. struct tm *tm;
  10000. pthread_t th_Status;
  10001. CurrentTime = time(NULL);
  10002. tm = localtime(&CurrentTime);
  10003. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10004. 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);
  10005. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10006. if(!interLock.isGetDiagnosticGoing)
  10007. {
  10008. interLock.isGetDiagnosticGoing = 1;
  10009. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10010. sleep(1);
  10011. }
  10012. else
  10013. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10014. return result;
  10015. }
  10016. void* GetDiagnosticsProcess(void* data)
  10017. {
  10018. pthread_detach(pthread_self());
  10019. mtrace();
  10020. int retriesInt=0, retryIntervalInt=0;
  10021. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10022. 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};
  10023. int port=0;
  10024. int isSuccess = FALSE;
  10025. char ftpbuf[200]={0};
  10026. char cmdBuf[2048];
  10027. struct tm *tmNow;
  10028. time_t CurrentTime;
  10029. struct tm tmStart;
  10030. struct tm tmStop;
  10031. CurrentTime = time(NULL);
  10032. tmNow=localtime(&CurrentTime);
  10033. uint16_t targetYear, targetMonth;
  10034. json_object *GetDiagnostics;
  10035. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10036. GetDiagnostics = json_tokener_parse(data);
  10037. if(!is_error(GetDiagnostics))
  10038. {
  10039. // Required data
  10040. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10041. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10042. // Optional data
  10043. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10044. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10045. else
  10046. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10047. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10048. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10049. else
  10050. retryIntervalInt = 30;
  10051. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10052. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10053. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10054. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10055. }
  10056. json_object_put(GetDiagnostics);
  10057. // Pack log to compress file
  10058. 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) &&
  10059. (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))
  10060. {
  10061. // Pack system log
  10062. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10063. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10064. targetYear = tmStart.tm_year;
  10065. targetMonth = tmStart.tm_mon;
  10066. do
  10067. {
  10068. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10069. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10070. if(targetMonth+1>=13)
  10071. {
  10072. targetYear += 1;
  10073. targetMonth = 1;
  10074. }
  10075. else
  10076. {
  10077. targetMonth += 1;
  10078. }
  10079. }while((targetYear < (tmNow->tm_year+1900)) ||
  10080. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10081. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10082. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10083. system(cmdBuf);
  10084. // Pack charging & event log
  10085. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10086. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10087. targetYear = tmStart.tm_year;
  10088. targetMonth = tmStart.tm_mon;
  10089. do
  10090. {
  10091. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10092. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10093. if(targetMonth+1>=13)
  10094. {
  10095. targetYear += 1;
  10096. targetMonth = 1;
  10097. }
  10098. else
  10099. {
  10100. targetMonth += 1;
  10101. }
  10102. }while((targetYear < (tmNow->tm_year+1900)) ||
  10103. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10104. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10105. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10106. system(cmdBuf);
  10107. // Combine log file
  10108. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10109. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10110. }
  10111. else
  10112. {
  10113. system("exec /root/logPackTools 'log' 6");
  10114. }
  10115. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10116. system(cmdBuf);
  10117. checkUploadLog();
  10118. //****************location*******************/
  10119. if(strcmp(locationstr,"")==0)
  10120. {
  10121. DEBUG_INFO("location is <Empty>!\n");
  10122. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10123. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10124. goto end;
  10125. }
  10126. memset(protocol, 0, ARRAY_SIZE(protocol));
  10127. memset(user, 0, ARRAY_SIZE(user) );
  10128. memset(password, 0, ARRAY_SIZE(password));
  10129. memset(host, 0, ARRAY_SIZE(host));
  10130. memset(path, 0, ARRAY_SIZE(path));
  10131. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10132. memset(host1, 0, ARRAY_SIZE(host1));
  10133. memset(path1, 0, ARRAY_SIZE(path1));
  10134. /*location: ftp://user:password@host:port/path*/
  10135. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10136. if((access(fnamePlusPath,F_OK))!=-1)
  10137. {
  10138. DEBUG_INFO("fnamePlusPath exist.\n");
  10139. }
  10140. else
  10141. {
  10142. DEBUG_INFO("fnamePlusPath not exist!\n");
  10143. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10144. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10145. goto end;
  10146. }
  10147. if(strchr(locationstr,'@')==NULL)
  10148. {
  10149. sscanf(locationstr,
  10150. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10151. protocol, host, &port, path);
  10152. strcpy(user,"anonymous");
  10153. strcpy(password,"");
  10154. }
  10155. else
  10156. {
  10157. //DEBUG_INFO("pch=%s\n", pch);
  10158. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10159. protocol, user, password, host, &port, path);
  10160. }
  10161. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10162. {
  10163. DEBUG_INFO("protocol is not ftp/http ! \n");
  10164. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10165. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10166. goto end;
  10167. }
  10168. if(strncmp(locationstr,"http", 4) == 0)
  10169. {
  10170. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10171. sprintf(ftppath,"/%s", path);
  10172. do
  10173. {
  10174. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10175. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10176. sleep(3);
  10177. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10178. if(!isSuccess)
  10179. {
  10180. DEBUG_INFO("Diagnostics fail.\n");
  10181. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10182. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10183. sleep(retryIntervalInt);
  10184. }
  10185. else
  10186. {
  10187. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10188. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10189. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10190. }
  10191. retriesInt--;
  10192. }while((isSuccess == 0)&&(retriesInt >= 0));
  10193. }
  10194. else
  10195. {
  10196. sscanf(host,"%[^/]%s",host1, path1);
  10197. if(strlen(path) > 0)
  10198. sprintf(ftppath,"/%s", path);
  10199. else
  10200. sprintf(ftppath,"/%s", path1);
  10201. int ftppathlen=strlen(ftppath);
  10202. int i=1;
  10203. char filenametemp[50];
  10204. while(i < ftppathlen)
  10205. {
  10206. int len=ftppathlen-i;
  10207. if(ftppath[len]== 47) // '/' ascll code: 47
  10208. {
  10209. DEBUG_INFO("find '/' all right\n");
  10210. break;
  10211. }
  10212. i=i+1;
  10213. }
  10214. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10215. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10216. filenametemp[i+1] = 0;
  10217. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10218. if(port == 0)
  10219. port = 21;
  10220. do
  10221. {
  10222. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10223. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10224. sleep(3);
  10225. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10226. if(!isSuccess)
  10227. {
  10228. DEBUG_INFO("Diagnostics fail.\n");
  10229. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10230. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10231. sleep(retryIntervalInt);
  10232. }
  10233. else
  10234. {
  10235. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10236. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10237. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10238. }
  10239. retriesInt--;
  10240. }while((!isSuccess)&&(retriesInt >= 0));
  10241. }
  10242. end:
  10243. system("rm -f /mnt/*");
  10244. sleep(5);
  10245. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10246. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10247. interLock.isGetDiagnosticGoing = 0;
  10248. pthread_exit(NULL);
  10249. }
  10250. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10251. {
  10252. mtrace();
  10253. int result = FAIL;
  10254. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10255. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10256. {
  10257. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10258. locallistVersion = -1;
  10259. }
  10260. else
  10261. {
  10262. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10263. locallistVersion = 0;
  10264. OCPP_getListVerion();
  10265. }
  10266. //from db.OCPP_getListVerion
  10267. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10268. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10269. sendGetLocalListVersionConfirmation(uuid,"");
  10270. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10271. return result;
  10272. }
  10273. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10274. {
  10275. mtrace();
  10276. int result = FAIL;
  10277. int connectorIdInt=-1;
  10278. int tempIndex = 0;
  10279. int connectorIdIsNULL, chargingProfileIsNULL;
  10280. char comfirmstr[20]={0};
  10281. char cmdBuf[512];
  10282. json_object *RemoteStartTransaction;
  10283. FILE *fp;
  10284. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10285. if(server_pending == TRUE)
  10286. {
  10287. return 0;
  10288. }
  10289. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10290. RemoteStartTransaction = json_tokener_parse(payload);
  10291. if(!is_error(RemoteStartTransaction))
  10292. {
  10293. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10294. {
  10295. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10296. }
  10297. else
  10298. {
  10299. connectorIdIsNULL = TRUE;
  10300. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10301. {
  10302. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10303. {
  10304. connectorIdIsNULL = FALSE;
  10305. connectorIdInt = (gun_index+1);
  10306. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10307. break;
  10308. }
  10309. }
  10310. }
  10311. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10312. {
  10313. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10314. // Required data
  10315. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10316. // Optional data
  10317. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10318. {
  10319. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10320. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10321. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10322. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10323. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10324. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10325. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10326. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10327. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10328. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10329. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10330. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10331. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10332. {
  10333. 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")));
  10334. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10335. 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"));
  10336. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10337. 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"));
  10338. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10339. 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")));
  10340. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10341. {
  10342. 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++)
  10343. {
  10344. 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"));
  10345. 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"));
  10346. 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)
  10347. 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"));
  10348. }
  10349. }
  10350. }
  10351. }
  10352. else
  10353. {
  10354. chargingProfileIsNULL = TRUE;
  10355. }
  10356. }
  10357. }
  10358. else
  10359. {
  10360. connectorIdIsNULL = TRUE;
  10361. }
  10362. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10363. {
  10364. DEBUG_WARN("Connector id is NULL\n.");
  10365. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10366. goto end;
  10367. }
  10368. /*
  10369. enum _SYSTEM_STATUS
  10370. {
  10371. S_BOOTING = 0,
  10372. S_IDLE, = 1
  10373. S_AUTHORIZING, = 2
  10374. S_REASSIGN_CHECK, = 3
  10375. S_REASSIGN, = 4
  10376. S_PRECHARGE, = 5
  10377. S_PREPARING_FOR_EV, = 6
  10378. S_PREPARING_FOR_EVSE, = 7
  10379. S_CHARGING, = 8
  10380. S_TERMINATING, = 9
  10381. S_COMPLETE, = 10
  10382. S_ALARM, = 11
  10383. S_FAULT = 12
  10384. }
  10385. */
  10386. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10387. {
  10388. //check Transaction active
  10389. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10390. {
  10391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10392. {
  10393. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10394. }
  10395. else
  10396. {
  10397. tempIndex = connectorIdInt -1;
  10398. }
  10399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10400. {
  10401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10402. {
  10403. 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))
  10404. {
  10405. //Reserved
  10406. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10407. }
  10408. 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))
  10409. {
  10410. //Reserved
  10411. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. else
  10416. {
  10417. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10418. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10419. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10420. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10421. {
  10422. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10424. goto end;
  10425. }
  10426. }//END FOR ELSE
  10427. }
  10428. }// END FOR CHAdeMO_QUANTITY
  10429. }
  10430. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10431. {
  10432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10433. {
  10434. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10435. }
  10436. else
  10437. {
  10438. tempIndex = connectorIdInt -1;
  10439. }
  10440. for (int index = 0; index < CCS_QUANTITY; index++)
  10441. {
  10442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10443. {
  10444. 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))
  10445. {
  10446. //Reserved
  10447. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10448. }
  10449. 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))
  10450. {
  10451. //Reserved
  10452. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10454. goto end;
  10455. }
  10456. else
  10457. {
  10458. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10459. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10460. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10461. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10462. {
  10463. DEBUG_WARN("CCS connector not allow start\n.");
  10464. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10465. goto end;
  10466. }
  10467. }// END FOR ELSE
  10468. }
  10469. }// END FOR CCS_QUANTITY
  10470. }
  10471. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10472. {
  10473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10474. {
  10475. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10476. }
  10477. else
  10478. {
  10479. tempIndex = connectorIdInt -1;
  10480. }
  10481. for (int index = 0; index < GB_QUANTITY; index++)
  10482. {
  10483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10484. {
  10485. 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))
  10486. {
  10487. //Reserved
  10488. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10489. }
  10490. 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))
  10491. {
  10492. //Reserved
  10493. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10494. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10495. goto end;
  10496. }
  10497. else
  10498. {
  10499. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10500. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10501. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10502. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10503. {
  10504. DEBUG_WARN("GB connector not allow start\n.");
  10505. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10506. goto end;
  10507. }
  10508. }// END FOR ELSE
  10509. }
  10510. } // END FOR GB_QUANTITY
  10511. }
  10512. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10513. {
  10514. tempIndex = connectorIdInt -1;
  10515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10516. {
  10517. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10518. {
  10519. 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))
  10520. {
  10521. //Reserved
  10522. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10523. }
  10524. 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))
  10525. {
  10526. //Reserved
  10527. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10529. goto end;
  10530. }
  10531. else
  10532. {
  10533. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10534. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10535. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10536. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10537. {
  10538. DEBUG_WARN("GB connector not allow start\n.");
  10539. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10540. goto end;
  10541. }
  10542. }// END FOR ELSE
  10543. }
  10544. } // END FOR GB_QUANTITY
  10545. }
  10546. else
  10547. {
  10548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10549. {
  10550. tempIndex = 2;
  10551. }
  10552. else
  10553. {
  10554. tempIndex = connectorIdInt -1;
  10555. }
  10556. for (int index = 0; index < AC_QUANTITY; index++)
  10557. {
  10558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10559. {
  10560. 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))
  10561. {
  10562. //Reserved
  10563. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10564. }
  10565. 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))
  10566. {
  10567. //Reserved
  10568. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10569. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10570. goto end;
  10571. }
  10572. else
  10573. {
  10574. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10575. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10576. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10577. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10578. {
  10579. DEBUG_WARN("AC connector not allow start\n.");
  10580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10581. goto end;
  10582. }
  10583. }//END FOR ELSE
  10584. }
  10585. }// END FOR AC_QUANTITY
  10586. }
  10587. if(chargingProfileIsNULL == FALSE)
  10588. {
  10589. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10590. {
  10591. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10592. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10593. //memset idTag
  10594. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10595. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10596. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10598. // Save profile to file
  10599. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10600. system(cmdBuf);
  10601. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10602. fp = fopen(cmdBuf, "w");
  10603. 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));
  10604. fclose(fp);
  10605. }
  10606. else
  10607. {
  10608. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10609. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10610. }
  10611. }
  10612. else
  10613. {
  10614. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10616. //memset idTag
  10617. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10618. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10619. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10621. }
  10622. }
  10623. else
  10624. {
  10625. DEBUG_WARN("Connector id over\n.");
  10626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10627. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10628. }
  10629. end:
  10630. json_object_put(RemoteStartTransaction);
  10631. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10632. {
  10633. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10634. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10635. }
  10636. //OCPP send RemoteStartConfirmation by first.
  10637. sendRemoteStartConfirmation(uuid, comfirmstr);
  10638. return result;
  10639. }
  10640. int handleRemoteStartRequest(char *uuid, char *payload)
  10641. {
  10642. mtrace();
  10643. int result = PASS;
  10644. int connectorIdInt=-1;
  10645. int tempIndex = 0;
  10646. char comfirmstr[20]={0};
  10647. char cmdBuf[512];
  10648. json_object *RemoteStartTransaction;
  10649. FILE *fp;
  10650. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10651. if(server_pending == TRUE)
  10652. {
  10653. result = FAIL;
  10654. }
  10655. RemoteStartTransaction = json_tokener_parse(payload);
  10656. if(!is_error(RemoteStartTransaction))
  10657. {
  10658. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10659. {
  10660. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10661. }
  10662. else
  10663. {
  10664. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10665. {
  10666. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10667. {
  10668. connectorIdInt = (gun_index+1);
  10669. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10670. break;
  10671. }
  10672. }
  10673. }
  10674. if(connectorIdInt == 0)
  10675. {
  10676. DEBUG_WARN("Connector id shall not equal 0.\n");
  10677. result = FAIL;
  10678. }
  10679. else if(connectorIdInt == -1)
  10680. {
  10681. DEBUG_INFO("Connector id does not specific.\n");
  10682. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10683. {
  10684. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10685. // Required data
  10686. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10687. // Optional data
  10688. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10689. {
  10690. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10691. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10692. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10693. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10694. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10695. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10696. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10697. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10698. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10699. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10700. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10701. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10702. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10703. {
  10704. 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")));
  10705. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10706. 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"));
  10707. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10708. 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"));
  10709. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10710. 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")));
  10711. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10712. {
  10713. 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++)
  10714. {
  10715. 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"));
  10716. 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"));
  10717. 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)
  10718. 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"));
  10719. }
  10720. }
  10721. }
  10722. }
  10723. else
  10724. {
  10725. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10726. }
  10727. }
  10728. }
  10729. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10730. {
  10731. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10732. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10733. // Required data
  10734. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10735. // Optional data
  10736. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10737. {
  10738. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10739. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10740. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10741. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10742. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10743. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10744. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10745. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10746. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10747. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10748. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10749. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10750. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10751. {
  10752. 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")));
  10753. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10754. 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"));
  10755. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10756. 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"));
  10757. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10758. 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")));
  10759. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10760. {
  10761. 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++)
  10762. {
  10763. 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"));
  10764. 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"));
  10765. 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)
  10766. 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"));
  10767. }
  10768. }
  10769. }
  10770. }
  10771. else
  10772. {
  10773. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10774. }
  10775. }
  10776. else
  10777. {
  10778. DEBUG_WARN("Connector id is over maximun value.\n");
  10779. result = FAIL;
  10780. }
  10781. }
  10782. if(result == PASS)
  10783. {
  10784. if(connectorIdInt > 0)
  10785. {
  10786. //check Transaction active
  10787. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10788. {
  10789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10790. {
  10791. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10792. }
  10793. else
  10794. {
  10795. tempIndex = connectorIdInt -1;
  10796. }
  10797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10798. {
  10799. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10800. {
  10801. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10802. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10803. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10804. {
  10805. //Reserved
  10806. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10807. }
  10808. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10809. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10810. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10811. {
  10812. //Reserved
  10813. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10815. goto end;
  10816. }
  10817. else
  10818. {
  10819. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10820. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10821. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10822. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10823. {
  10824. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10825. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10826. goto end;
  10827. }
  10828. }//END FOR ELSE
  10829. }
  10830. }// END FOR CHAdeMO_QUANTITY
  10831. }
  10832. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10833. {
  10834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10835. {
  10836. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10837. }
  10838. else
  10839. {
  10840. tempIndex = connectorIdInt -1;
  10841. }
  10842. for (int index = 0; index < CCS_QUANTITY; index++)
  10843. {
  10844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10845. {
  10846. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10847. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10848. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10849. {
  10850. //Reserved
  10851. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10852. }
  10853. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10854. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10855. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10856. {
  10857. //Reserved
  10858. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10860. goto end;
  10861. }
  10862. else
  10863. {
  10864. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10865. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10866. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10867. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10868. {
  10869. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10871. goto end;
  10872. }
  10873. }// END FOR ELSE
  10874. }
  10875. }// END FOR CCS_QUANTITY
  10876. }
  10877. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10878. {
  10879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10880. {
  10881. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10882. }
  10883. else
  10884. {
  10885. tempIndex = connectorIdInt -1;
  10886. }
  10887. for (int index = 0; index < GB_QUANTITY; index++)
  10888. {
  10889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10890. {
  10891. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10892. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10893. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10894. {
  10895. //Reserved
  10896. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10897. }
  10898. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10899. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10900. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10901. {
  10902. //Reserved
  10903. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10905. goto end;
  10906. }
  10907. else
  10908. {
  10909. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10910. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10911. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10912. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10913. {
  10914. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10916. goto end;
  10917. }
  10918. }// END FOR ELSE
  10919. }
  10920. } // END FOR GB_QUANTITY
  10921. }
  10922. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10923. {
  10924. tempIndex = connectorIdInt -1;
  10925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10926. {
  10927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10928. {
  10929. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10930. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10931. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10932. {
  10933. //Reserved
  10934. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10935. }
  10936. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10937. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10938. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10939. {
  10940. //Reserved
  10941. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10942. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10943. goto end;
  10944. }
  10945. else
  10946. {
  10947. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10948. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10949. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10950. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10951. {
  10952. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10953. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10954. goto end;
  10955. }
  10956. }// END FOR ELSE
  10957. }
  10958. } // END FOR GB_QUANTITY
  10959. }
  10960. else
  10961. {
  10962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10963. {
  10964. tempIndex = 2;
  10965. }
  10966. else
  10967. {
  10968. tempIndex = connectorIdInt -1;
  10969. }
  10970. for (int index = 0; index < AC_QUANTITY; index++)
  10971. {
  10972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10973. {
  10974. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10975. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10976. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10977. {
  10978. //Reserved
  10979. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10980. }
  10981. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10982. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10983. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10984. {
  10985. //Reserved
  10986. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10987. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10988. goto end;
  10989. }
  10990. else
  10991. {
  10992. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10993. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10994. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10995. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10996. {
  10997. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10999. goto end;
  11000. }
  11001. }//END FOR ELSE
  11002. }
  11003. }// END FOR AC_QUANTITY
  11004. }
  11005. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11006. {
  11007. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11008. {
  11009. // Save profile to file
  11010. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11011. system(cmdBuf);
  11012. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11013. fp = fopen(cmdBuf, "w");
  11014. 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));
  11015. fclose(fp);
  11016. }
  11017. else
  11018. {
  11019. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11020. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11021. goto end;
  11022. }
  11023. }
  11024. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11026. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11027. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11028. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11030. }
  11031. else
  11032. {
  11033. uint8_t isHasIdleConnector = FALSE;
  11034. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11035. {
  11036. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11037. {
  11038. isHasIdleConnector = TRUE;
  11039. break;
  11040. }
  11041. }
  11042. if(isHasIdleConnector == TRUE)
  11043. {
  11044. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11045. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11046. {
  11047. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11048. {
  11049. // Save profile to file
  11050. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11051. system(cmdBuf);
  11052. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11053. fp = fopen(cmdBuf, "w");
  11054. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11055. fclose(fp);
  11056. refreshStartTimer(&clientTime.RemoteStartWait);
  11057. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11058. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11059. }
  11060. else
  11061. {
  11062. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11064. }
  11065. }
  11066. else
  11067. {
  11068. refreshStartTimer(&clientTime.RemoteStartWait);
  11069. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11071. }
  11072. }
  11073. else
  11074. {
  11075. DEBUG_INFO("There is not any connector is idle.\n");
  11076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11077. }
  11078. }
  11079. }
  11080. else
  11081. {
  11082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11083. }
  11084. end:
  11085. json_object_put(RemoteStartTransaction);
  11086. sendRemoteStartConfirmation(uuid, comfirmstr);
  11087. return result;
  11088. }
  11089. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11090. {
  11091. mtrace();
  11092. int result = FAIL;
  11093. int match = FALSE;
  11094. int GunNO = 0;
  11095. int tempIndex = 0;
  11096. int transactionIdInt=0;
  11097. int transactionIdIsNULL= TRUE;
  11098. char comfirmstr[20];
  11099. json_object *RemoteStopTransaction;
  11100. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11101. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11102. if(server_pending == TRUE)
  11103. {
  11104. return 0;
  11105. }
  11106. RemoteStopTransaction = json_tokener_parse(payload);
  11107. if(!is_error(RemoteStopTransaction))
  11108. {
  11109. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11110. {
  11111. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11112. transactionIdIsNULL = FALSE;
  11113. }
  11114. }
  11115. json_object_put(RemoteStopTransaction);
  11116. if(transactionIdIsNULL == FALSE)
  11117. {
  11118. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11119. {
  11120. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11121. {
  11122. //check Transaction active
  11123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11124. {
  11125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11126. {
  11127. tempIndex = ((gun_index==2) ? 1: 0);
  11128. }
  11129. else
  11130. {
  11131. tempIndex = gun_index;
  11132. }
  11133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11134. {
  11135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11136. {
  11137. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11138. {
  11139. match = TRUE;
  11140. GunNO = gun_index;
  11141. }
  11142. }
  11143. }// END FOR CHAdeMO_QUANTITY
  11144. }
  11145. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11146. {
  11147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11148. {
  11149. tempIndex = ((gun_index==2) ? 1: 0);
  11150. }
  11151. else
  11152. {
  11153. tempIndex = gun_index;
  11154. }
  11155. for (int index = 0; index < CCS_QUANTITY; index++)
  11156. {
  11157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11158. {
  11159. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11160. {
  11161. match = TRUE;
  11162. GunNO = gun_index;
  11163. }
  11164. }
  11165. }// END FOR CCS_QUANTITY
  11166. }
  11167. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11168. {
  11169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11170. {
  11171. tempIndex = ((gun_index==2) ? 1: 0);
  11172. }
  11173. else
  11174. {
  11175. tempIndex = gun_index;
  11176. }
  11177. for (int index = 0; index < GB_QUANTITY; index++)
  11178. {
  11179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11180. {
  11181. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11182. {
  11183. match = TRUE;
  11184. GunNO = gun_index;
  11185. }
  11186. }
  11187. }// END FOR GB_QUANTITY
  11188. }
  11189. else if(gunType[gun_index] == GUN_TYPE_DO)
  11190. {
  11191. tempIndex = gun_index;
  11192. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11193. {
  11194. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11195. {
  11196. 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
  11197. {
  11198. match = TRUE;
  11199. GunNO = gun_index;
  11200. }
  11201. }
  11202. }// END FOR GB_QUANTITY
  11203. }
  11204. else
  11205. {
  11206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11207. {
  11208. tempIndex = 2;
  11209. }
  11210. else
  11211. {
  11212. tempIndex = gun_index;
  11213. }
  11214. for (int index = 0; index < AC_QUANTITY; index++)
  11215. {
  11216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11217. {
  11218. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11219. {
  11220. match = TRUE;
  11221. GunNO = gun_index;
  11222. }
  11223. }
  11224. }// END FOR CHAdeMO_QUANTITY
  11225. } // END FOR AC ELSE
  11226. }// CHECK IF ResponseTransactionId == transactionIdInt
  11227. }//END FOR
  11228. if( match == TRUE)
  11229. {
  11230. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11232. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11233. }
  11234. else
  11235. {
  11236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11237. }
  11238. }
  11239. else
  11240. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11241. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11242. return result;
  11243. }
  11244. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11245. {
  11246. mtrace();
  11247. int result = FAIL;
  11248. int connectorIdInt=0, reservationIdInt=0;
  11249. int tempIndex = 0;
  11250. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11251. char comfirmstr[20]={0};
  11252. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11253. int c = 0;
  11254. char *loc;
  11255. //char *ptr;
  11256. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11257. strcpy(sstrtemp, stringtrimspace(payload));
  11258. //***(1)connectorId ****/
  11259. c=0;
  11260. loc = strstr(sstrtemp, "connectorId");
  11261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11262. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11263. {
  11264. sstr[c] = loc[strlen("connectorId")+2+c];
  11265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11266. c++;
  11267. }
  11268. sstr[c] = '\0';
  11269. connectorIdInt = atoi(sstr);
  11270. //***(2)expiryDate ****/
  11271. loc = strstr(sstrtemp, "expiryDate");
  11272. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11273. c = 0;
  11274. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11275. {
  11276. sstr[c] = loc[3+strlen("expiryDate")+c];
  11277. c++;
  11278. }
  11279. sstr[c] = '\0';
  11280. strcpy(expiryDatestr, sstr);
  11281. //***(3)idTag ****/
  11282. loc = strstr(sstrtemp, "idTag");
  11283. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11284. c = 0;
  11285. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11286. {
  11287. sstr[c] = loc[3+strlen("idTag")+c];
  11288. c++;
  11289. }
  11290. sstr[c] = '\0';
  11291. strcpy(idTagstr, sstr);
  11292. //***(4)parentIdTag ****/
  11293. loc = strstr(sstrtemp, "parentIdTag");
  11294. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11295. c = 0;
  11296. if(loc == NULL)
  11297. {
  11298. strcpy(parentIdTagstr, "");
  11299. }
  11300. else
  11301. {
  11302. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11303. {
  11304. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11305. c++;
  11306. }
  11307. sstr[c] = '\0';
  11308. strcpy(parentIdTagstr, sstr);
  11309. }
  11310. //***(5)reservationId ****/
  11311. c=0;
  11312. loc = strstr(sstrtemp, "reservationId");
  11313. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11314. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11315. {
  11316. sstr[c] = loc[strlen("reservationId")+2+c];
  11317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11318. c++;
  11319. }
  11320. sstr[c] = '\0';
  11321. reservationIdInt = atoi(sstr);
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11323. /*
  11324. enum SYSTEM_STATUS
  11325. {
  11326. SYS_MODE_BOOTING = 0,
  11327. SYS_MODE_IDLE = 1,
  11328. SYS_MODE_AUTHORIZING = 2,
  11329. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11330. SYS_MODE_REASSIGN = 4,
  11331. SYS_MODE_PREPARING = 5,
  11332. SYS_MODE_PREPARE_FOR_EV = 6,
  11333. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11334. SYS_MODE_CHARGING = 8,
  11335. SYS_MODE_TERMINATING = 9,
  11336. SYS_MODE_COMPLETE = 10,
  11337. SYS_MODE_ALARM = 11,
  11338. SYS_MODE_FAULT = 12,
  11339. SYS_MODE_RESERVATION = 13,
  11340. SYS_MODE_BOOKING = 14,
  11341. SYS_MODE_MAINTAIN = 15,
  11342. SYS_MODE_DEBUG = 16,
  11343. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11344. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11345. SYS_MODE_UPDATE = 19
  11346. };
  11347. */
  11348. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11349. {
  11350. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11351. goto end;
  11352. }
  11353. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11354. {
  11355. //check Transaction active
  11356. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11357. {
  11358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11359. {
  11360. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11361. }
  11362. else
  11363. {
  11364. tempIndex = connectorIdInt -1;
  11365. }
  11366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11367. {
  11368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11369. {
  11370. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11371. {
  11372. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11373. {
  11374. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11375. {
  11376. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11379. }
  11380. else
  11381. {
  11382. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11384. }
  11385. }
  11386. 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'))
  11387. {
  11388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11389. }
  11390. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11391. {
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11393. }
  11394. else
  11395. {
  11396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11397. }
  11398. }
  11399. 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
  11400. {
  11401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11402. }
  11403. }
  11404. else
  11405. {
  11406. //replace reservation
  11407. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11409. }
  11410. }
  11411. } // END FOR CHAdeMO_QUANTITY
  11412. }
  11413. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11414. {
  11415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11416. {
  11417. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11418. }
  11419. else
  11420. {
  11421. tempIndex = connectorIdInt -1;
  11422. }
  11423. for (int index = 0; index < CCS_QUANTITY; index++)
  11424. {
  11425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11426. {
  11427. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11428. {
  11429. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11430. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11431. {
  11432. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11433. {
  11434. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11437. }
  11438. else
  11439. {
  11440. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11442. }
  11443. }
  11444. 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'))
  11445. {
  11446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11447. }
  11448. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11449. {
  11450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11451. }
  11452. else
  11453. {
  11454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11455. }
  11456. }
  11457. 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
  11458. {
  11459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11460. }
  11461. }
  11462. else
  11463. {
  11464. //replace reservation
  11465. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11467. }
  11468. }
  11469. } // END FOR CCS_QUANTITY
  11470. }
  11471. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11472. {
  11473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11474. {
  11475. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11476. }
  11477. else
  11478. {
  11479. tempIndex = connectorIdInt -1;
  11480. }
  11481. for (int index = 0; index < GB_QUANTITY; index++)
  11482. {
  11483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11484. {
  11485. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11486. {
  11487. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11488. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11489. {
  11490. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11491. {
  11492. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11493. {
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11495. }
  11496. else
  11497. {
  11498. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11500. }
  11501. }
  11502. 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'))
  11503. {
  11504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11505. }
  11506. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11507. {
  11508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11509. }
  11510. else
  11511. {
  11512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11513. }
  11514. }
  11515. 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
  11516. {
  11517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11518. }
  11519. }
  11520. else
  11521. {
  11522. //replace reservation
  11523. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11525. }
  11526. }
  11527. }// END FOR GB_QUANTITY
  11528. }
  11529. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11530. {
  11531. tempIndex = connectorIdInt -1;
  11532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11533. {
  11534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11535. {
  11536. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11537. {
  11538. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11539. 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
  11540. {
  11541. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11542. {
  11543. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11544. {
  11545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11546. }
  11547. else
  11548. {
  11549. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11551. }
  11552. }
  11553. 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'))
  11554. {
  11555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11556. }
  11557. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11558. {
  11559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11560. }
  11561. else
  11562. {
  11563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11564. }
  11565. }
  11566. 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
  11567. {
  11568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11569. }
  11570. }
  11571. else
  11572. {
  11573. //replace reservation
  11574. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11576. }
  11577. }
  11578. }// END FOR GB_QUANTITY
  11579. }
  11580. else
  11581. {
  11582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11583. {
  11584. tempIndex = 2;
  11585. }
  11586. else
  11587. {
  11588. tempIndex = (connectorIdInt -1);
  11589. }
  11590. for (int index = 0; index < AC_QUANTITY; index++)
  11591. {
  11592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11593. {
  11594. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11595. {
  11596. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11597. {
  11598. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11599. {
  11600. 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))
  11601. {
  11602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11603. }
  11604. else
  11605. {
  11606. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11608. }
  11609. }
  11610. 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'))
  11611. {
  11612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11613. }
  11614. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11615. {
  11616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11617. }
  11618. else
  11619. {
  11620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11621. }
  11622. }
  11623. 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
  11624. {
  11625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11626. }
  11627. }
  11628. else
  11629. {
  11630. //replace reservation
  11631. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11633. }
  11634. }
  11635. } // END FOR AC_QUANTITY
  11636. }
  11637. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11638. }
  11639. else if(connectorIdInt == 0)
  11640. {
  11641. //check Transaction active
  11642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11643. {
  11644. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11645. {
  11646. 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'))
  11647. {
  11648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11649. goto end;
  11650. }
  11651. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11652. {
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11654. goto end;
  11655. }
  11656. 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
  11657. {
  11658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11659. goto end;
  11660. }
  11661. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11662. {
  11663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11664. goto end;
  11665. }
  11666. }
  11667. }// END FOR CHAdeMO_QUANTITY
  11668. for (int index = 0; index < CCS_QUANTITY; index++)
  11669. {
  11670. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11671. {
  11672. 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'))
  11673. {
  11674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11675. goto end;
  11676. }
  11677. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11678. {
  11679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11680. goto end;
  11681. }
  11682. 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
  11683. {
  11684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11685. goto end;
  11686. }
  11687. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11688. {
  11689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11690. goto end;
  11691. }
  11692. }
  11693. } // END FOR CCS_QUANTITY
  11694. for (int index = 0; index < GB_QUANTITY; index++)
  11695. {
  11696. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11697. {
  11698. 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'))
  11699. {
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11701. goto end;
  11702. }
  11703. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11704. {
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11706. goto end;
  11707. }
  11708. 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
  11709. {
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11711. goto end;
  11712. }
  11713. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11714. {
  11715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11716. goto end;
  11717. }
  11718. }
  11719. } // END FOR GB_QUANTITY
  11720. for (int index = 0; index < AC_QUANTITY; index++)
  11721. {
  11722. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11723. {
  11724. 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'))
  11725. {
  11726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11727. goto end;
  11728. }
  11729. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11730. {
  11731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11732. goto end;
  11733. }
  11734. 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
  11735. {
  11736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11737. goto end;
  11738. }
  11739. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11740. {
  11741. 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))
  11742. {
  11743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11744. goto end;
  11745. }
  11746. }
  11747. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11748. {
  11749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11750. goto end;
  11751. }
  11752. }
  11753. }// END FOR AC_QUANTITY
  11754. //The connectorId is 0
  11755. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11757. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11758. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11759. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11760. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11761. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11762. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11763. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11764. result = TRUE;
  11765. return result;
  11766. }
  11767. else
  11768. {
  11769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11770. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11771. }
  11772. if(strcmp(comfirmstr,"Accepted") == 0)
  11773. {
  11774. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11775. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11776. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11777. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11778. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11779. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11780. result = TRUE;
  11781. return result;
  11782. }
  11783. end:
  11784. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11785. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11786. return result;
  11787. }
  11788. int handleResetRequest(char *uuid, char *payload)
  11789. {
  11790. mtrace();
  11791. int result = FAIL;
  11792. char sstr[10]={0},sstrtemp[30]={ 0 };
  11793. char typestr[10]={0};
  11794. char comfirmstr[20]={0};
  11795. int c = 0;
  11796. char *loc;
  11797. DEBUG_INFO("handleResetRequest...\n");
  11798. strcpy(sstrtemp, stringtrimspace(payload));
  11799. loc = strstr(sstrtemp, "type");
  11800. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11801. c = 0;
  11802. while (loc[3+strlen("type")+c] != '\"')
  11803. {
  11804. sstr[c] = loc[3+strlen("type")+c];
  11805. c++;
  11806. }
  11807. sstr[c] = '\0';
  11808. strcpy(typestr,sstr);
  11809. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11810. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11811. {
  11812. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11813. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11814. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11815. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11816. }
  11817. else
  11818. {
  11819. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11820. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11821. result = PASS;
  11822. }
  11823. sendResetConfirmation(uuid, comfirmstr);
  11824. return result;
  11825. }
  11826. int handleSendLocalListRequest(char *uuid, char *payload)
  11827. {
  11828. mtrace();
  11829. int result = FAIL;
  11830. char comfirmstr[20];
  11831. int checkState_Faulted = FALSE;
  11832. json_object *SendLocalList;
  11833. DEBUG_INFO("handleSendLocalListRequest...\n");
  11834. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11835. {
  11836. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11837. goto end;
  11838. }
  11839. //check Charge Point state
  11840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11841. {
  11842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11843. {
  11844. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11845. }
  11846. }
  11847. for (int index = 0; index < CCS_QUANTITY; index++)
  11848. {
  11849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11850. {
  11851. checkState_Faulted = TRUE; //OCPP Status
  11852. }
  11853. }
  11854. for (int index = 0; index < GB_QUANTITY; index++)
  11855. {
  11856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11857. {
  11858. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11859. }
  11860. }
  11861. //check Charge Point state
  11862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11863. {
  11864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11865. {
  11866. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11867. }
  11868. }
  11869. //check Charge Point state
  11870. for (int index = 0; index < AC_QUANTITY; index++)
  11871. {
  11872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11873. {
  11874. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11875. }
  11876. }
  11877. if(checkState_Faulted == TRUE)
  11878. {
  11879. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11880. goto end;
  11881. }
  11882. // Parsing payload
  11883. SendLocalList = json_tokener_parse(payload);
  11884. if(!is_error(SendLocalList))
  11885. {
  11886. // Required data
  11887. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11888. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11889. // Optional data
  11890. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11891. {
  11892. //Check UpdateType
  11893. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11894. {
  11895. //Local list full update
  11896. DEBUG_INFO("Local list full update.\n");
  11897. locallistVersion = 0;
  11898. OCPP_getListVerion();
  11899. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11900. {
  11901. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11902. goto end;
  11903. }*/
  11904. OCPP_cleanLocalList();
  11905. }
  11906. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11907. {
  11908. //Local list different update
  11909. DEBUG_INFO("Local list different update.\n");
  11910. locallistVersion = 0;
  11911. OCPP_getListVerion();
  11912. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11913. {
  11914. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11915. goto end;
  11916. }
  11917. }
  11918. else
  11919. {
  11920. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11921. goto end;
  11922. }
  11923. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11924. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11925. {
  11926. 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")));
  11927. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11928. {
  11929. 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")));
  11930. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11931. 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")));
  11932. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11933. 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")));
  11934. }
  11935. // Add to db
  11936. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11937. {
  11938. //Local list full update
  11939. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11940. idx,
  11941. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11942. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11943. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11944. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11945. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11946. // update list
  11947. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11948. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11949. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11950. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11951. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11952. }
  11953. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11954. {
  11955. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11956. idx,
  11957. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11958. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11959. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11960. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11961. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11962. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11963. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11964. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11965. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11966. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11967. }
  11968. }
  11969. }
  11970. else
  11971. {
  11972. //Check UpdateType
  11973. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11974. {
  11975. //Local list full update
  11976. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11977. OCPP_cleanLocalList();
  11978. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11979. goto end;
  11980. }
  11981. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11982. {
  11983. //Local list different update
  11984. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11985. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11986. goto end;
  11987. }
  11988. }
  11989. result = PASS;
  11990. }
  11991. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11992. end:
  11993. json_object_put(SendLocalList);
  11994. sendSendLocalListConfirmation(uuid, comfirmstr);
  11995. return result;
  11996. }
  11997. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11998. {
  11999. mtrace();
  12000. int result = FAIL;
  12001. struct StructSetChargingProfile SetProfileReq = {0};
  12002. int tempchargingProfileIdInt;
  12003. int tempstackLevelInt;
  12004. int chargingSchedulePeriodCount = 0;
  12005. char comfirmstr[20]={0};
  12006. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  12007. char rmFileCmd[128]={0};
  12008. int profileQuantity = 0;
  12009. int replaceableProfileCnt = 0;
  12010. json_object *SetChargingProfile;
  12011. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12012. SetChargingProfile = json_tokener_parse(payload);
  12013. if(!is_error(SetChargingProfile))
  12014. {
  12015. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12016. {
  12017. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12018. }
  12019. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12020. {
  12021. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12022. {
  12023. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12024. }
  12025. else
  12026. {
  12027. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12028. DEBUG_WARN("Cannot find chargingProfileId field.");
  12029. goto end;
  12030. }
  12031. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12032. {
  12033. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12034. }
  12035. else
  12036. {
  12037. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12038. DEBUG_WARN("Cannot find stackLevel field.");
  12039. goto end;
  12040. }
  12041. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12042. {
  12043. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12044. }
  12045. else
  12046. {
  12047. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12048. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12049. goto end;
  12050. }
  12051. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12052. {
  12053. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12054. }
  12055. else
  12056. {
  12057. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12058. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12059. goto end;
  12060. }
  12061. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12062. {
  12063. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12064. }
  12065. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12066. {
  12067. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12068. }
  12069. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12070. {
  12071. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12072. }
  12073. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12074. {
  12075. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12076. }
  12077. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12078. {
  12079. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12080. {
  12081. 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")));
  12082. }
  12083. else
  12084. {
  12085. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12086. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12087. goto end;
  12088. }
  12089. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12090. {
  12091. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12092. }
  12093. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12094. {
  12095. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12096. }
  12097. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12098. {
  12099. 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")));
  12100. }
  12101. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12102. {
  12103. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12104. if(chargingSchedulePeriodCount <= 10)
  12105. {
  12106. 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++)
  12107. {
  12108. 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)
  12109. {
  12110. 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"));
  12111. }
  12112. else
  12113. {
  12114. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12115. DEBUG_WARN("Cannot find startPeriod field.");
  12116. goto end;
  12117. }
  12118. 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)
  12119. {
  12120. 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"));
  12121. }
  12122. else
  12123. {
  12124. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12125. DEBUG_WARN("Cannot find limit field.");
  12126. goto end;
  12127. }
  12128. 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)
  12129. {
  12130. 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"));
  12131. }
  12132. }
  12133. }
  12134. }
  12135. else
  12136. {
  12137. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12138. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12139. goto end;
  12140. }
  12141. }
  12142. else
  12143. {
  12144. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12145. DEBUG_WARN("Cannot find chargingSchedule field.");
  12146. goto end;
  12147. }
  12148. }
  12149. }
  12150. // Profile periods quantity check
  12151. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12152. {
  12153. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12154. goto end;
  12155. }
  12156. // Check invalid limit
  12157. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12158. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12159. {
  12160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12161. {
  12162. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12163. {
  12164. 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)))) ||
  12165. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12166. {
  12167. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12168. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12169. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12170. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12171. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12172. goto end;
  12173. }
  12174. }
  12175. }
  12176. else
  12177. {
  12178. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12179. {
  12180. 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) ||
  12181. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12182. {
  12183. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12184. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12185. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12186. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12187. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12188. goto end;
  12189. }
  12190. }
  12191. }
  12192. }
  12193. // Profile purpose info check
  12194. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12195. {
  12196. FILE *fp;
  12197. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12198. if(SetProfileReq.ConnectorId != 0)
  12199. {
  12200. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12201. goto end;
  12202. }
  12203. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12204. if (!fp)
  12205. {
  12206. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12207. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12208. }
  12209. else
  12210. {
  12211. char *line = NULL;
  12212. size_t len = 0;
  12213. while(getline(&line, &len, fp) != -1)
  12214. {
  12215. json_object *obj = NULL;
  12216. obj = json_tokener_parse(line);
  12217. if(is_error(obj))
  12218. {
  12219. DEBUG_ERROR("Parse txProfile from file error.\n");
  12220. }
  12221. else
  12222. {
  12223. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12224. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12225. {
  12226. profileQuantity += 1;
  12227. }
  12228. else
  12229. replaceableProfileCnt += 1;
  12230. }
  12231. }
  12232. }
  12233. fclose(fp);
  12234. }
  12235. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12236. {
  12237. FILE *fp;
  12238. char filename[128]={0};
  12239. int tmpProfileQuantity;
  12240. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12241. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12242. {
  12243. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12244. goto end;
  12245. }
  12246. if(SetProfileReq.ConnectorId == 0)
  12247. {
  12248. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12249. {
  12250. tmpProfileQuantity = 0;
  12251. memset(filename, 0, ARRAY_SIZE(filename));
  12252. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12253. fp = fopen(filename, "r");
  12254. if (!fp)
  12255. {
  12256. DEBUG_INFO("%s does not create.\n", filename);
  12257. fp = fopen(filename, "w+");
  12258. }
  12259. else
  12260. {
  12261. char *line = NULL;
  12262. size_t len = 0;
  12263. while(getline(&line, &len, fp) != -1)
  12264. {
  12265. json_object *obj = NULL;
  12266. obj = json_tokener_parse(line);
  12267. if(is_error(obj))
  12268. {
  12269. DEBUG_ERROR("Parse txProfile from file error.\n");
  12270. }
  12271. else
  12272. {
  12273. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12274. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12275. {
  12276. tmpProfileQuantity += 1;
  12277. }
  12278. else
  12279. replaceableProfileCnt += 1;
  12280. }
  12281. }
  12282. }
  12283. fclose(fp);
  12284. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12285. }
  12286. }
  12287. else
  12288. {
  12289. memset(filename, 0, ARRAY_SIZE(filename));
  12290. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12291. fp = fopen(filename, "r");
  12292. if (!fp)
  12293. {
  12294. DEBUG_INFO("%s does not create.\n", filename);
  12295. fp = fopen(filename, "w+");
  12296. }
  12297. else
  12298. {
  12299. char *line = NULL;
  12300. size_t len = 0;
  12301. while(getline(&line, &len, fp) != -1)
  12302. {
  12303. json_object *obj = NULL;
  12304. obj = json_tokener_parse(line);
  12305. if(is_error(obj))
  12306. {
  12307. DEBUG_ERROR("Parse txProfile from file error.\n");
  12308. }
  12309. else
  12310. {
  12311. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12312. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12313. {
  12314. profileQuantity += 1;
  12315. }
  12316. else
  12317. replaceableProfileCnt += 1;
  12318. }
  12319. }
  12320. }
  12321. fclose(fp);
  12322. }
  12323. }
  12324. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12325. {
  12326. int isMatchTransactiodId= FALSE;
  12327. FILE *fp;
  12328. char filename[128]={0};
  12329. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12330. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12331. if(SetProfileReq.ConnectorId == 0)
  12332. {
  12333. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12334. goto end;
  12335. }
  12336. int tempIndex = 0;
  12337. //check Transaction active
  12338. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12339. {
  12340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12341. {
  12342. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12343. }
  12344. else
  12345. {
  12346. tempIndex = SetProfileReq.ConnectorId -1;
  12347. }
  12348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12349. {
  12350. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12351. {
  12352. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12353. {
  12354. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12355. {
  12356. isMatchTransactiodId = TRUE;
  12357. break;
  12358. }
  12359. }
  12360. }
  12361. }
  12362. }
  12363. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12364. {
  12365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12366. {
  12367. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12368. }
  12369. else
  12370. {
  12371. tempIndex = SetProfileReq.ConnectorId -1;
  12372. }
  12373. for (int index = 0; index < CCS_QUANTITY; index++)
  12374. {
  12375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12376. {
  12377. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12378. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12379. {
  12380. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12381. {
  12382. isMatchTransactiodId = TRUE;
  12383. break;
  12384. }
  12385. }
  12386. }
  12387. }
  12388. }
  12389. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12390. {
  12391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12392. {
  12393. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12394. }
  12395. else
  12396. {
  12397. tempIndex = SetProfileReq.ConnectorId -1;
  12398. }
  12399. for (int index = 0; index < GB_QUANTITY; index++)
  12400. {
  12401. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12402. {
  12403. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12404. {
  12405. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12406. {
  12407. isMatchTransactiodId = TRUE;
  12408. break;
  12409. }
  12410. }
  12411. }
  12412. }
  12413. }
  12414. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12415. {
  12416. tempIndex = SetProfileReq.ConnectorId -1;
  12417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12418. {
  12419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12420. {
  12421. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12422. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12423. {
  12424. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12425. {
  12426. isMatchTransactiodId = TRUE;
  12427. break;
  12428. }
  12429. }
  12430. }
  12431. }
  12432. }
  12433. else
  12434. {
  12435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12436. {
  12437. tempIndex = 2;
  12438. }
  12439. else
  12440. {
  12441. tempIndex = (SetProfileReq.ConnectorId -1);
  12442. }
  12443. for (int index = 0; index < AC_QUANTITY; index++)
  12444. {
  12445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12446. {
  12447. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12448. {
  12449. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12450. {
  12451. isMatchTransactiodId = TRUE;
  12452. break;
  12453. }
  12454. }
  12455. }
  12456. }
  12457. }
  12458. //check Transaction active
  12459. if(isMatchTransactiodId == FALSE)
  12460. {
  12461. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12462. goto end;
  12463. }
  12464. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12465. {
  12466. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12467. goto end;
  12468. }
  12469. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12470. fp = fopen(filename, "r");
  12471. if (!fp)
  12472. {
  12473. DEBUG_INFO("%s does not create.\n", filename);
  12474. fp = fopen(filename, "w+");
  12475. }
  12476. else
  12477. {
  12478. char *line = NULL;
  12479. size_t len = 0;
  12480. while(getline(&line, &len, fp) != -1)
  12481. {
  12482. json_object *obj = NULL;
  12483. obj = json_tokener_parse(line);
  12484. if(is_error(obj))
  12485. {
  12486. DEBUG_ERROR("Parse txProfile from file error.\n");
  12487. }
  12488. else
  12489. {
  12490. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12491. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12492. {
  12493. profileQuantity += 1;
  12494. }
  12495. else
  12496. replaceableProfileCnt += 1;
  12497. }
  12498. }
  12499. }
  12500. fclose(fp);
  12501. }
  12502. // Check ChargeProfileMaxStackLevel
  12503. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12504. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12505. {
  12506. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12507. goto end;
  12508. }
  12509. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12510. {
  12511. FILE *fp;
  12512. char dataLine[4096]={0};
  12513. char fnametemp[128]={0};
  12514. int tmpProfileQuantity;
  12515. //Check ChargePointMaxProfile.json exit
  12516. profileQuantity = 0;
  12517. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12518. {
  12519. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12520. //Check Charging Profile Count
  12521. tmpProfileQuantity = 0;
  12522. while(fscanf(fp, "%s", dataLine) != EOF)
  12523. {
  12524. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12525. {
  12526. profileQuantity += 1;
  12527. tmpProfileQuantity += 1;
  12528. }
  12529. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12530. }
  12531. fclose(fp);
  12532. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12533. }
  12534. //Check TxDefaultProfile_%d.json
  12535. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12536. {
  12537. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12538. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12539. if((access(fnametemp,F_OK))!=-1)
  12540. {
  12541. fp = fopen(fnametemp, "r");
  12542. //Check Charging Profile Count
  12543. tmpProfileQuantity = 0;
  12544. while(fscanf(fp, "%s", dataLine) != EOF)
  12545. {
  12546. //DEBUG_INFO("word=%s\n",word);
  12547. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12548. {
  12549. profileQuantity += 1;
  12550. tmpProfileQuantity += 1;
  12551. }
  12552. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12553. }
  12554. fclose(fp);
  12555. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12556. }
  12557. }
  12558. //Check TxProfile_%d.json
  12559. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12560. {
  12561. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12562. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12563. if((access(fnametemp,F_OK))!=-1)
  12564. {
  12565. fp = fopen(fnametemp, "r");
  12566. //Check Charging Profile Count
  12567. tmpProfileQuantity = 0;
  12568. while(fscanf(fp, "%s", dataLine) != EOF)
  12569. {
  12570. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12571. {
  12572. profileQuantity += 1;
  12573. tmpProfileQuantity += 1;
  12574. }
  12575. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12576. }
  12577. fclose(fp);
  12578. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12579. }
  12580. }
  12581. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12582. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12583. // To check total Profile quantity
  12584. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12585. {
  12586. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12587. {
  12588. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12589. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12590. goto end;
  12591. }
  12592. }
  12593. else
  12594. {
  12595. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12596. {
  12597. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12598. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12599. goto end;
  12600. }
  12601. }
  12602. }
  12603. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12604. //**********************************Write to File********************************************************/
  12605. {
  12606. FILE *infile;
  12607. FILE *outfile;
  12608. char dataLine[4096]={0};
  12609. char filename[128]={0};
  12610. int chkChar=0;
  12611. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12612. {
  12613. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12614. {
  12615. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12616. }
  12617. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12618. {
  12619. if(SetProfileReq.ConnectorId==0)
  12620. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12621. else
  12622. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12623. }
  12624. else
  12625. {
  12626. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12627. }
  12628. infile = fopen (filename, "r");
  12629. outfile = fopen (tempfile, "w");
  12630. chkChar = fgetc(infile);
  12631. rewind(infile);
  12632. if(chkChar == EOF)
  12633. {
  12634. // Profile is empty
  12635. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12636. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12637. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12638. fclose(infile);
  12639. fclose(outfile);
  12640. sprintf(rmFileCmd,"rm -f %s",filename);
  12641. system(rmFileCmd);
  12642. rename(tempfile, filename);
  12643. }
  12644. else
  12645. {
  12646. // Profile is not empty
  12647. int ChargingProfileAdded = FALSE;
  12648. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12649. {
  12650. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12651. json_object *tmpChargingProfile;
  12652. tmpChargingProfile = json_tokener_parse(dataLine);
  12653. if(!is_error(SetChargingProfile))
  12654. {
  12655. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12656. {
  12657. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12658. {
  12659. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12660. }
  12661. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12662. {
  12663. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12664. }
  12665. }
  12666. }
  12667. json_object_put(tmpChargingProfile);
  12668. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12669. {
  12670. if(ChargingProfileAdded == FALSE)
  12671. {
  12672. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12673. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12674. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12675. ChargingProfileAdded = TRUE;
  12676. }
  12677. }
  12678. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12679. {
  12680. if(ChargingProfileAdded == FALSE)
  12681. {
  12682. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12683. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12684. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12685. ChargingProfileAdded = TRUE;
  12686. }
  12687. }
  12688. else
  12689. {
  12690. fprintf(outfile,"%s\n",dataLine);
  12691. if(ChargingProfileAdded == FALSE)
  12692. {
  12693. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12694. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12695. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12696. ChargingProfileAdded = TRUE;
  12697. }
  12698. }
  12699. } // end of while loop
  12700. fclose(infile);
  12701. fclose(outfile);
  12702. sprintf(rmFileCmd,"rm -f %s",filename);
  12703. system(rmFileCmd);
  12704. rename(tempfile, filename);
  12705. }
  12706. }
  12707. sleep(1);
  12708. result = TRUE;
  12709. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12710. }
  12711. end:
  12712. json_object_put(SetChargingProfile);
  12713. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12714. {
  12715. if(SetProfileReq.ConnectorId == 0)
  12716. {
  12717. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12718. {
  12719. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12720. }
  12721. }
  12722. else
  12723. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12724. }
  12725. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12726. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12727. return result;
  12728. }
  12729. int handleTriggerMessageRequest(char *uuid, char *payload)
  12730. {
  12731. mtrace();
  12732. int result = FAIL;
  12733. int connectorIdIsNULL = FALSE;
  12734. int connectorIdInt =0;
  12735. char sstr[40]={0},sstrtemp[100]={ 0 };
  12736. char requestedMessagestr[40]={0};
  12737. char comfirmstr[20]={0};
  12738. int c = 0;
  12739. char *loc;
  12740. DEBUG_INFO("handleTriggerMessageRequest\n");
  12741. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12742. strcpy(sstrtemp, stringtrimspace(payload));
  12743. c = 0;
  12744. loc = strstr(sstrtemp, "requestedMessage");
  12745. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12746. {
  12747. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12748. c++;
  12749. }
  12750. sstr[c] = '\0';
  12751. strcpy(requestedMessagestr, sstr);
  12752. c = 0;
  12753. loc = strstr(sstrtemp, "connectorId");
  12754. if(loc == NULL)
  12755. {
  12756. connectorIdIsNULL = TRUE;
  12757. }
  12758. else
  12759. {
  12760. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12761. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12762. {
  12763. sstr[c] = loc[strlen("connectorId")+2+c];
  12764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12765. c++;
  12766. }
  12767. sstr[c] = '\0';
  12768. connectorIdInt = atoi(sstr);
  12769. }
  12770. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12771. {
  12772. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12773. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12774. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12775. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12776. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12777. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12778. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12779. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12780. {
  12781. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12782. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12783. return TRUE;
  12784. }
  12785. else
  12786. {
  12787. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12788. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12789. }
  12790. }
  12791. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12792. {
  12793. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12794. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12795. return TRUE;
  12796. }
  12797. //==========================
  12798. // Trigger message
  12799. //==========================
  12800. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12801. {
  12802. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12803. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12804. {
  12805. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12806. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12807. }
  12808. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12809. }
  12810. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12811. {
  12812. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12813. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12814. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12815. }
  12816. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12817. {
  12818. //sendBootNotificationRequest();
  12819. server_sign = FALSE;
  12820. }
  12821. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12822. {
  12823. refreshStartTimer(&clientTime.Heartbeat);
  12824. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12825. }
  12826. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12827. {
  12828. if(connectorIdIsNULL == FALSE)
  12829. {
  12830. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12831. {
  12832. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12833. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12834. }
  12835. }
  12836. else
  12837. {
  12838. for(int idx=0;idx< gunTotalNumber;idx++)
  12839. {
  12840. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12841. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12842. }
  12843. }
  12844. }
  12845. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12846. {
  12847. if(connectorIdIsNULL == FALSE)
  12848. {
  12849. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12850. {
  12851. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12852. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12853. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12854. }
  12855. }
  12856. else
  12857. {
  12858. for(int idx=0;idx< gunTotalNumber;idx++)
  12859. {
  12860. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12861. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12862. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12863. }
  12864. }
  12865. }
  12866. return result;
  12867. }
  12868. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12869. {
  12870. mtrace();
  12871. int result = FAIL;
  12872. int connectorIdInt =0;
  12873. char comfirmstr[20]={0};
  12874. int tempIndex = 0;
  12875. json_object *UnlockConnector;
  12876. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12877. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12878. UnlockConnector = json_tokener_parse(payload);
  12879. if(!is_error(UnlockConnector))
  12880. {
  12881. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12882. {
  12883. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12884. }
  12885. }
  12886. json_object_put(UnlockConnector);
  12887. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12888. if(gunTotalNumber == 0)
  12889. {
  12890. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12891. goto end;
  12892. }
  12893. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12894. {
  12895. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12896. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12897. goto end;
  12898. }
  12899. else
  12900. {
  12901. //check Transaction active
  12902. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12903. {
  12904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12905. {
  12906. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12907. }
  12908. else
  12909. {
  12910. tempIndex = connectorIdInt -1;
  12911. }
  12912. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12913. {
  12914. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12915. {
  12916. //stop Transaction
  12917. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12918. }
  12919. }
  12920. }
  12921. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12922. {
  12923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12924. {
  12925. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12926. }
  12927. else
  12928. {
  12929. tempIndex = connectorIdInt -1;
  12930. }
  12931. for (int index = 0; index < CCS_QUANTITY; index++)
  12932. {
  12933. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12934. {
  12935. //stop Transaction
  12936. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12937. }
  12938. }
  12939. }
  12940. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12941. {
  12942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12943. {
  12944. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12945. }
  12946. else
  12947. {
  12948. tempIndex = connectorIdInt -1;
  12949. }
  12950. for (int index = 0; index < GB_QUANTITY; index++)
  12951. {
  12952. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12953. {
  12954. //stop Transaction
  12955. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12956. }
  12957. }
  12958. }
  12959. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12960. {
  12961. tempIndex = connectorIdInt -1;
  12962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12963. {
  12964. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12965. {
  12966. //stop Transaction
  12967. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12968. }
  12969. }
  12970. }
  12971. else
  12972. {
  12973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12974. {
  12975. tempIndex = 2;
  12976. }
  12977. else
  12978. {
  12979. tempIndex = connectorIdInt-1;
  12980. }
  12981. for (int index = 0; index < AC_QUANTITY; index++)
  12982. {
  12983. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12984. {
  12985. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12986. }
  12987. }
  12988. }
  12989. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12990. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12991. result = TRUE;
  12992. return result;
  12993. }
  12994. end:
  12995. //json_object_put(obj); --- remove temporally
  12996. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12997. return result;
  12998. }
  12999. static char UpdateFirmwarepayloadData[300]={0};
  13000. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13001. {
  13002. mtrace();
  13003. int result = FAIL;
  13004. pthread_t t;
  13005. sendUpdateFirmwareConfirmation(uuid);
  13006. memset(UpdateFirmwarepayloadData, 0, 300);
  13007. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13008. if(!interLock.isUpdateFirmwareGoing)
  13009. {
  13010. interLock.isUpdateFirmwareGoing = 1;
  13011. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13012. sleep(1);
  13013. }
  13014. else
  13015. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13016. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  13017. return result;
  13018. }
  13019. void *UpdateFirmwareProcess(void *data)
  13020. {
  13021. pthread_detach(pthread_self());
  13022. mtrace();
  13023. int retriesInt =0, retryIntervalInt=0;
  13024. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  13025. int port=0;
  13026. char locationstr[512]={0}, retrieveDatestr[36]={0};
  13027. int isSuccess = 0;
  13028. char ftpbuf[512];
  13029. char temp[100];
  13030. char * pch;
  13031. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13032. json_object *UpdateFirmware;
  13033. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13034. if(!is_error(UpdateFirmware))
  13035. {
  13036. // Required data
  13037. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13038. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13039. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13040. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13041. // Optional data
  13042. if(json_object_object_get(UpdateFirmware, "retries"))
  13043. {
  13044. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13045. }
  13046. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13047. {
  13048. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13049. }
  13050. }
  13051. json_object_put(UpdateFirmware);
  13052. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13053. memset(path, 0, ARRAY_SIZE(path));
  13054. // Wait retrieveData
  13055. if(strlen(retrieveDatestr) > 10)
  13056. {
  13057. do
  13058. {
  13059. sleep(1);
  13060. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13061. }
  13062. // Ready to download
  13063. system("rm -f /mnt/*");
  13064. if(strncmp(locationstr,"http", 4) == 0)
  13065. {
  13066. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13067. sprintf(ftppath,"/%s", path);
  13068. DEBUG_INFO("locationstr: %s\n", locationstr);
  13069. DEBUG_INFO("protocol: %s\n",protocol);
  13070. DEBUG_INFO("host: %s\n",host);
  13071. DEBUG_INFO("path: %s\n",path);
  13072. DEBUG_INFO("ftppath: %s\n",ftppath);
  13073. int ftppathlen=strlen(ftppath);
  13074. int i=1;
  13075. char filenametemp[50];
  13076. while(i < ftppathlen)
  13077. {
  13078. int len=ftppathlen-i;
  13079. if(ftppath[len]== 47) // '/' ascll code: 47
  13080. {
  13081. DEBUG_INFO("compare '/' all right\n");
  13082. break;
  13083. }
  13084. i=i+1;
  13085. }
  13086. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13087. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13088. filenametemp[i+1] = 0;
  13089. do
  13090. {
  13091. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13092. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13093. sleep(1);
  13094. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13095. if(!isSuccess)
  13096. {
  13097. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13098. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13099. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13100. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13101. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13102. }
  13103. else
  13104. {
  13105. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13106. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13107. }
  13108. retriesInt--;
  13109. }while((isSuccess == 0)&&(retriesInt >= 0));
  13110. }
  13111. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13112. {
  13113. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13114. memset(temp, 0, ARRAY_SIZE(temp));
  13115. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13116. strcpy(ftpbuf, locationstr);
  13117. int ftppathlen=strlen(ftpbuf);
  13118. int i=1;
  13119. char filenametemp[50];
  13120. while(i < ftppathlen)
  13121. {
  13122. int len=ftppathlen-i;
  13123. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13124. {
  13125. DEBUG_INFO(" compare '/' all right\n");
  13126. break;
  13127. }
  13128. i=i+1;
  13129. }
  13130. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13131. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13132. filenametemp[i+1] = 0;
  13133. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13134. pch=strchr(temp,'@');
  13135. if(pch==NULL)
  13136. {
  13137. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13138. protocol, host, &port, path);
  13139. strcpy(user,"anonymous");
  13140. strcpy(password,"");
  13141. }
  13142. else
  13143. {
  13144. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13145. protocol, user, host, &port, path);
  13146. }
  13147. sscanf(host,"%[^/]%s",host1, path1);
  13148. sprintf(ftppath,"%s:/%s", host,path);
  13149. if(port == 0)
  13150. {
  13151. port = 21;
  13152. }
  13153. do
  13154. {
  13155. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13156. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13157. sleep(1);
  13158. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13159. if(!isSuccess)
  13160. {
  13161. //BulldogUtil.sleepMs(interval*1000);
  13162. DEBUG_INFO("Update firmware request and download file fail.\n");
  13163. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13164. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13165. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13166. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13167. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13168. }
  13169. else
  13170. {
  13171. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13172. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13173. }
  13174. retriesInt--;
  13175. }while((!isSuccess)&&(retriesInt >= 0));
  13176. }
  13177. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13178. {
  13179. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13180. memset(temp, 0, ARRAY_SIZE(temp));
  13181. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13182. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13183. int ftppathlen=strlen(ftpbuf);
  13184. int i=1;
  13185. char filenametemp[50];
  13186. while(i < ftppathlen)
  13187. {
  13188. int len=ftppathlen-i;
  13189. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13190. {
  13191. DEBUG_INFO(" compare '/' all right\n");
  13192. break;
  13193. }
  13194. i=i+1;
  13195. }
  13196. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13197. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13198. filenametemp[i+1] = 0;
  13199. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13200. pch=strchr(temp,'@');
  13201. if(pch==NULL)
  13202. {
  13203. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13204. protocol, host, &port, path);
  13205. strcpy(user,"anonymous");
  13206. strcpy(password,"");
  13207. }
  13208. else
  13209. {
  13210. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13211. protocol, user, password, host, &port, path);
  13212. }
  13213. sscanf(host,"%[^/]%s",host1, path1);
  13214. sprintf(ftppath,"%s", path1);
  13215. //DEBUG_INFO("protocol =%s\n",protocol);
  13216. //DEBUG_INFO("user =%s\n",user);
  13217. //DEBUG_INFO("password =%s\n",password);
  13218. //DEBUG_INFO("host1 =%s\n",host1);
  13219. //DEBUG_INFO("port =%d\n",port);
  13220. //DEBUG_INFO("path1 =%s\n",path1);
  13221. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13222. //ftpFile(host, user, password, port, ftppath, fname);
  13223. //download firmware pthred
  13224. if(port == 0)
  13225. {
  13226. port = 21;
  13227. }
  13228. do
  13229. {
  13230. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13231. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13232. sleep(1);
  13233. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13234. if(!isSuccess)
  13235. {
  13236. //BulldogUtil.sleepMs(interval*1000);
  13237. DEBUG_INFO("Update firmware request and download file fail.\n");
  13238. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13239. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13240. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13241. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13242. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13243. }
  13244. else
  13245. {
  13246. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13247. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13248. }
  13249. retriesInt--;
  13250. }while((!isSuccess)&&(retriesInt >= 0));
  13251. }
  13252. else
  13253. {
  13254. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13255. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13256. sleep(1);
  13257. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13258. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13259. }
  13260. // OCPPPH only, must announce CSU upgrade firmware
  13261. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13262. interLock.isUpdateFirmwareGoing = 0;
  13263. pthread_exit(NULL);
  13264. }
  13265. int handleCertificateSignedRequest(char *uuid, char *payload)
  13266. {
  13267. mtrace();
  13268. int result = PASS;
  13269. json_object *CertificateSigned;
  13270. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13271. CertificateSigned = json_tokener_parse(payload);
  13272. if(!is_error(CertificateSigned))
  13273. {
  13274. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13275. }
  13276. json_object_put(CertificateSigned);
  13277. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13278. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13279. fclose(fp);
  13280. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13281. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13282. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13283. sendCertificateSignedConfirmation(uuid);
  13284. return result;
  13285. }
  13286. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13287. {
  13288. mtrace();
  13289. int result = PASS;
  13290. json_object *DeleteCertificate;
  13291. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13292. DeleteCertificate = json_tokener_parse(payload);
  13293. if(!is_error(DeleteCertificate))
  13294. {
  13295. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13296. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13297. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13298. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13299. }
  13300. json_object_put(DeleteCertificate);
  13301. /*
  13302. * TODO: Delete certificateSigned process
  13303. */
  13304. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13305. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13306. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13307. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13308. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13309. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13310. sendDeleteCertificateConfirmation(uuid);
  13311. return result;
  13312. }
  13313. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13314. {
  13315. mtrace();
  13316. int result = PASS;
  13317. json_object *ExtendedTriggerMessage;
  13318. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13319. ExtendedTriggerMessage = json_tokener_parse(payload);
  13320. if(!is_error(ExtendedTriggerMessage))
  13321. {
  13322. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13323. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13324. {
  13325. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13326. }
  13327. else
  13328. {
  13329. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13330. }
  13331. }
  13332. json_object_put(ExtendedTriggerMessage);
  13333. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13334. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13335. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13336. {
  13337. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13338. }
  13339. else
  13340. {
  13341. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13342. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13343. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13344. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13345. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13346. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13347. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13348. {
  13349. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13350. }
  13351. else
  13352. {
  13353. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13354. }
  13355. }
  13356. sendExtendedTriggerMessageConfirmation(uuid);
  13357. //==========================
  13358. // Trigger message
  13359. //==========================
  13360. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13361. {
  13362. //sendBootNotificationRequest();
  13363. server_sign = FALSE;
  13364. }
  13365. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13366. {
  13367. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13368. }
  13369. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13370. {
  13371. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13372. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13373. {
  13374. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13375. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13376. }
  13377. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13378. }
  13379. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13380. {
  13381. refreshStartTimer(&clientTime.Heartbeat);
  13382. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13383. }
  13384. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13385. {
  13386. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13387. {
  13388. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13389. }
  13390. else
  13391. {
  13392. for(int idx=0;idx< gunTotalNumber;idx++)
  13393. {
  13394. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13395. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13396. }
  13397. }
  13398. }
  13399. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13400. {
  13401. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13402. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13403. {
  13404. 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\" &");
  13405. }
  13406. }
  13407. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13408. {
  13409. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13410. {
  13411. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13412. }
  13413. else
  13414. {
  13415. for(int idx=0;idx< gunTotalNumber;idx++)
  13416. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13417. }
  13418. }
  13419. return result;
  13420. }
  13421. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13422. {
  13423. mtrace();
  13424. int result = PASS;
  13425. json_object *GetInstalledCertificateIds;
  13426. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13427. GetInstalledCertificateIds = json_tokener_parse(payload);
  13428. if(!is_error(GetInstalledCertificateIds))
  13429. {
  13430. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13431. }
  13432. json_object_put(GetInstalledCertificateIds);
  13433. /*
  13434. * TODO: Return installed certificate process
  13435. */
  13436. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13437. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13438. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13439. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13440. sendGetInstalledCertificateIdsConfirmation(uuid);
  13441. return result;
  13442. }
  13443. int handleGetLogRequest(char *uuid, char *payload)
  13444. {
  13445. mtrace();
  13446. int result = PASS;
  13447. json_object *GetLog;
  13448. DEBUG_INFO("handleGetLogRequest...\n");
  13449. GetLog = json_tokener_parse(payload);
  13450. if(!is_error(GetLog))
  13451. {
  13452. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13453. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13454. if(json_object_object_get(GetLog, "retries") != NULL)
  13455. {
  13456. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13457. }
  13458. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13459. {
  13460. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13461. }
  13462. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13463. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13464. {
  13465. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13466. }
  13467. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13468. {
  13469. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13470. }
  13471. }
  13472. json_object_put(GetLog);
  13473. /*
  13474. * TODO: Upload log process
  13475. */
  13476. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13477. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13478. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13479. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13480. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13481. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13482. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13483. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13484. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13485. sendGetLogConfirmation(uuid);
  13486. return result;
  13487. }
  13488. int handleInstallCertificateRequest(char *uuid, char *payload)
  13489. {
  13490. mtrace();
  13491. int result = PASS;
  13492. json_object *InstallCertificate;
  13493. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13494. InstallCertificate = json_tokener_parse(payload);
  13495. if(!is_error(InstallCertificate))
  13496. {
  13497. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13498. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13499. /*
  13500. * TODO: Install certificate process
  13501. */
  13502. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13503. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13504. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13505. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13506. sendInstallCertificateConfirmation(uuid);
  13507. }
  13508. json_object_put(InstallCertificate);
  13509. return result;
  13510. }
  13511. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13512. {
  13513. mtrace();
  13514. int result = PASS;
  13515. json_object *SignedUpdateFirmware;
  13516. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13517. SignedUpdateFirmware = json_tokener_parse(payload);
  13518. if(!is_error(SignedUpdateFirmware))
  13519. {
  13520. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13521. {
  13522. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13523. }
  13524. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13525. {
  13526. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13527. }
  13528. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13529. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13530. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13531. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13532. {
  13533. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13534. }
  13535. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13536. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13537. }
  13538. json_object_put(SignedUpdateFirmware);
  13539. /*
  13540. * TODO: Upgrade firmware process
  13541. */
  13542. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13543. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13544. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13545. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13546. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13547. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13548. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13549. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13550. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13551. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13552. sendInstallCertificateConfirmation(uuid);
  13553. return result;
  13554. }
  13555. int handleUnknownRequest(char *uuid, char *payload)
  13556. {
  13557. mtrace();
  13558. int result = PASS;
  13559. DEBUG_INFO("handleUnknownRequest...\n");
  13560. sendUnknownConfirmation(uuid);
  13561. result = PASS;
  13562. return result;
  13563. }
  13564. //==========================================
  13565. // Handle server response routine
  13566. //==========================================
  13567. void handleAuthorizeResponse(char *payload, int gun_index)
  13568. {
  13569. mtrace();
  13570. char expiryDatestr[36]={0};
  13571. char parentIdTagstr[21]={0};
  13572. char statusstr[20]={0};
  13573. int expiryDateISNULL=FALSE;
  13574. int parentIdTagISNULL=FALSE;
  13575. DEBUG_INFO("handleAuthorizeResponse...\n");
  13576. json_object *Authorize;
  13577. Authorize = json_tokener_parse(payload);
  13578. if(!is_error(Authorize))
  13579. {
  13580. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13581. {
  13582. // Required data
  13583. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13584. // Optional data
  13585. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13586. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13587. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13588. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13589. }
  13590. }
  13591. json_object_put(Authorize);
  13592. if(expiryDateISNULL == FALSE)
  13593. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13594. if(parentIdTagISNULL == FALSE)
  13595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13597. //Update idTag information to authorization cache if supproted
  13598. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13599. {
  13600. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13601. }
  13602. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13603. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13604. authorizeRetryTimes = 0;
  13605. }
  13606. void handleBootNotificationResponse(char *payload, int gun_index)
  13607. {
  13608. mtrace();
  13609. char statusStr[12]={0};
  13610. char currentTimeStr[30]={0};
  13611. int intervalInt = 0;
  13612. DEBUG_INFO("handleBootNotificationResponse...\n");
  13613. json_object *BootNotification;
  13614. BootNotification = json_tokener_parse(payload);
  13615. if(!is_error(BootNotification))
  13616. {
  13617. // Required data
  13618. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13619. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13620. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13621. }
  13622. json_object_put(BootNotification);
  13623. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13624. BootNotificationInterval = intervalInt;
  13625. //write back to ShmOCPP16DataPH->BootNotification
  13626. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13627. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13628. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13629. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13630. {
  13631. BootNotificationInterval = 0;
  13632. if((intervalInt == 0) || (intervalInt >= 10))
  13633. {
  13634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13635. HeartBeatWaitTime = intervalInt;
  13636. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13637. }
  13638. server_sign = TRUE;
  13639. server_pending =FALSE;
  13640. }
  13641. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13642. {
  13643. server_pending = TRUE;
  13644. }
  13645. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13646. srand(time(NULL));
  13647. refreshStartTimer(&clientTime.Heartbeat);
  13648. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13649. SetOcppConnStatus(TRUE);
  13650. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13651. }
  13652. void handleDataTransferResponse(char *payload, int gun_index)
  13653. {
  13654. json_object *DataTransfer = json_tokener_parse(payload);
  13655. if(!is_error(DataTransfer))
  13656. {
  13657. // Required data
  13658. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13659. // Optional data
  13660. if(json_object_object_get(DataTransfer, "data") != NULL)
  13661. {
  13662. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13663. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13664. if(!is_error(Data))
  13665. {
  13666. if(json_object_object_get(Data, "msgId") != NULL)
  13667. {
  13668. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13669. {
  13670. 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")));
  13671. }
  13672. }
  13673. }
  13674. json_object_put(Data);
  13675. }
  13676. }
  13677. json_object_put(DataTransfer);
  13678. }
  13679. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13680. {
  13681. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13682. //struct json_object *obj;
  13683. // obj = json_tokener_parse(payload);
  13684. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13685. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13686. //No fields are defined.
  13687. }
  13688. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13689. {
  13690. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13691. //struct json_object *obj;
  13692. // obj = json_tokener_parse(payload);
  13693. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13694. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13695. //No fields are defined.
  13696. }
  13697. void handleHeartbeatResponse(char *payload, int gun_index)
  13698. {
  13699. mtrace();
  13700. DEBUG_INFO("handleHeartbeatResponse...\n");
  13701. json_object *Heartbeat;
  13702. Heartbeat = json_tokener_parse(payload);
  13703. if(!is_error(Heartbeat))
  13704. {
  13705. // Required data
  13706. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13707. }
  13708. json_object_put(Heartbeat);
  13709. if(FirstHeartBeat == 0)
  13710. {
  13711. FirstHeartBeat = 1;
  13712. DEBUG_INFO("FirstHeartBeat \n");
  13713. }
  13714. HeartBeatWithNOResponse = 0;
  13715. refreshStartTimer(&clientTime.Heartbeat);
  13716. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13717. }
  13718. void handleMeterValuesResponse(char *payload, int gun_index)
  13719. {
  13720. mtrace();
  13721. DEBUG_INFO("handleMeterValuesResponse...\n");
  13722. isQueueSendable = 1;
  13723. }
  13724. void handleStartTransactionResponse(char *payload, int gun_index)
  13725. {
  13726. mtrace();
  13727. //int transactionIdInt = 0;
  13728. FILE *outfile;
  13729. char data[100]={0};
  13730. DEBUG_INFO("handleStartTransactionResponse...\n");
  13731. json_object *StartTransaction;
  13732. StartTransaction = json_tokener_parse(payload);
  13733. if(!is_error(StartTransaction))
  13734. {
  13735. // Required data
  13736. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13737. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13738. // Optional data
  13739. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13740. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13741. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13742. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13743. }
  13744. json_object_put(StartTransaction);
  13745. isQueueSendable = 1;
  13746. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13747. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13748. //-----------Start : write to the Queue TransactionId file -----------------//
  13749. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13750. {}
  13751. else
  13752. {
  13753. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13754. if(log == NULL)
  13755. {
  13756. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13757. return ;
  13758. }
  13759. else
  13760. {
  13761. fclose(log);
  13762. }
  13763. }
  13764. // open file for writing
  13765. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13766. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13767. {
  13768. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13769. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13770. fputs(data, outfile);
  13771. fclose (outfile);
  13772. }
  13773. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13774. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13775. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13776. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13777. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13778. }
  13779. void handleStatusNotificationResponse(char *payload, int gun_index)
  13780. {
  13781. mtrace();
  13782. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13783. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13784. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13785. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13786. }
  13787. void handleStopTransactionnResponse(char *payload, int gun_index)
  13788. {
  13789. mtrace();
  13790. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13791. json_object *StopTransaction;
  13792. StopTransaction = json_tokener_parse(payload);
  13793. if(!is_error(StopTransaction))
  13794. {
  13795. // Optional data
  13796. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13797. {
  13798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13799. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13800. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13801. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13803. }
  13804. }
  13805. json_object_put(StopTransaction);
  13806. isQueueSendable = 1;
  13807. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13808. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13809. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13810. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13811. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13812. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13813. }
  13814. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13815. {
  13816. mtrace();
  13817. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13818. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13819. }
  13820. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13821. {
  13822. mtrace();
  13823. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13824. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13825. }
  13826. void handleSignCertificateResponse(char *payload, int gun_index)
  13827. {
  13828. mtrace();
  13829. DEBUG_INFO("handleSignCertificateResponse...\n");
  13830. json_object *SignCertificate;
  13831. SignCertificate = json_tokener_parse(payload);
  13832. if(!is_error(SignCertificate))
  13833. {
  13834. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13835. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13836. }
  13837. json_object_put(SignCertificate);
  13838. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13839. }
  13840. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13841. {
  13842. mtrace();
  13843. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13844. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13845. }
  13846. //==========================================
  13847. // Handle Error routine
  13848. //==========================================
  13849. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13850. {
  13851. mtrace();
  13852. #ifdef SystemLogMessage
  13853. DEBUG_INFO("errorCode: %s\n", errorCode);
  13854. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13855. DEBUG_INFO("errorDetails: %s\n", payload);
  13856. #endif
  13857. }
  13858. //===============================================
  13859. // Common routine
  13860. //===============================================
  13861. int initialConfigurationTable(void)
  13862. {
  13863. //clock_t start_t, end_t, total_t;
  13864. FILE *fp;
  13865. FILE *outfile;
  13866. char str[512]={0};
  13867. char sstr[256]={0};
  13868. int c = 0;
  13869. char *loc;
  13870. int confVersion = 14;
  13871. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13872. //start_t = clock();
  13873. //printf("Starting of the program, start_t = %ld\n", start_t);
  13874. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13875. // Check configuration file size is correct
  13876. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13877. {
  13878. struct stat st;
  13879. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13880. if(st.st_size < 3100)
  13881. {
  13882. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13883. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13884. }
  13885. }
  13886. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13887. {
  13888. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13889. if(outfile == NULL)
  13890. {
  13891. DEBUG_INFO("Error opening file\n");
  13892. return FALSE;
  13893. }
  13894. /*Core Profile*/
  13895. //AllowOfflineTxForUnknownId
  13896. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13900. //AuthorizationCacheEnabled
  13901. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13905. //AuthorizeRemoteTxRequests
  13906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13910. //BlinkRepeat
  13911. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13915. //ClockAlignedDataInterval
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13920. //ConnectionTimeOut
  13921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13925. //GetConfigurationMaxKeys
  13926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13928. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13930. // HeartbeatInterval
  13931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13935. // LightIntensity
  13936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13940. // LocalAuthorizeOffline
  13941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13945. // LocalPreAuthorize
  13946. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13950. // MaxEnergyOnInvalidId
  13951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13955. // MeterValuesAlignedData
  13956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13958. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13959. 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" );
  13960. else
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13963. // MeterValuesAlignedDataMaxLength
  13964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13968. else
  13969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13971. // MeterValuesSampledData
  13972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13975. 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" );
  13976. else
  13977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13979. // MeterValuesSampledDataMaxLength
  13980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13984. else
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13987. // MeterValueSampleInterval
  13988. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13992. // MinimumStatusDuration
  13993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13996. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13998. // NumberOfConnectors
  13999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14002. {
  14003. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14004. }
  14005. else
  14006. {
  14007. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14008. }
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14010. // ResetRetries
  14011. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14015. // ConnectorPhaseRotation
  14016. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14020. // ConnectorPhaseRotationMaxLength
  14021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14025. // StopTransactionOnEVSideDisconnect
  14026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14030. // StopTransactionOnInvalidId
  14031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14035. // StopTxnAlignedData
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14040. // StopTxnAlignedDataMaxLength
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14045. // StopTxnSampledData
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14050. else
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14053. // StopTxnSampledDataMaxLength
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14057. {
  14058. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14059. }
  14060. else
  14061. {
  14062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14063. }
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14065. // SupportedFeatureProfiles
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14070. // SupportedFeatureProfilesMaxLength
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14075. // TransactionMessageAttempts
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14079. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14081. // TransactionMessageRetryInterval
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14085. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14087. // UnlockConnectorOnEVSideDisconnect
  14088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14092. // WebSocketPingInterval
  14093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14097. // QueueOffLineMeterValues
  14098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14102. // AuthorizationKey
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14107. // SecurityProfile
  14108. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14110. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14112. // DefaultPrice
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14117. // CustomDisplayCostAndPrice
  14118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14122. // CustomIdleFeeAfterStop
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14127. // SystemUptimeSec
  14128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14132. // FreeVend
  14133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14137. // FreeVendIdtag
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14142. // OcppServer
  14143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14145. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14147. // MaintainServer
  14148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14150. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14152. // StatusNotificationPeriodically
  14153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14157. // StatusNotificationInterval
  14158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14162. // isEnableLocalPowerSharing
  14163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14167. // PowerSharingServerIP
  14168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14170. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14172. // EVCCID_PREFIX
  14173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14177. // Configuration Version
  14178. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14182. //* Local Auth List Management Profile*/
  14183. #if 0
  14184. //For OCTT Test Case
  14185. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14188. #endif
  14189. #if 1
  14190. //LocalAuthListEnabled
  14191. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14195. #endif
  14196. //LocalAuthListMaxLength
  14197. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14201. //SendLocalListMaxLength
  14202. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14206. //ReserveConnectorZeroSupported
  14207. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14211. //* Smart Charging Profile */
  14212. //ChargeProfileMaxStackLevel
  14213. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14217. // ChargingScheduleAllowedChargingRateUnit
  14218. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14222. // ChargingScheduleMaxPeriods
  14223. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14227. // ConnectorSwitch3to1PhaseSupported
  14228. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14232. // MaxChargingProfilesInstalled
  14233. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14237. fclose(outfile);
  14238. }
  14239. else
  14240. {
  14241. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14242. char keystr[60]={0};
  14243. char readonlystr[10]={0};
  14244. char valuestr[256]={0};
  14245. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14246. if(fp == NULL) {
  14247. DEBUG_INFO("Error opening file");
  14248. return FALSE;
  14249. }
  14250. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14251. {
  14252. //DEBUG_INFO("Get Configuration \n");
  14253. if(strlen(str) > 0)
  14254. {
  14255. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14256. //*************************key*********************************/
  14257. if(strstr(str, "key") != NULL)
  14258. {
  14259. loc = strstr(str, "key");
  14260. c = 0;
  14261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14262. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14263. {
  14264. sstr[c] = loc[strlen("key")+3+c];
  14265. c++;
  14266. }
  14267. sstr[c] = '\0';
  14268. strcpy(keystr,sstr);
  14269. }
  14270. //*************************readonly*********************************/
  14271. if(strstr(str, "readonly") != NULL)
  14272. {
  14273. loc = strstr(str, "readonly");
  14274. c = 0;
  14275. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14276. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14277. {
  14278. sstr[c] = loc[strlen("readonly")+2+c];
  14279. c++;
  14280. }
  14281. sstr[c] = '\0';
  14282. strcpy(readonlystr,sstr);
  14283. }
  14284. //*************************value*********************************/
  14285. if(strstr(str, "value") != NULL)
  14286. {
  14287. loc = strstr(str, "value");
  14288. c = 0;
  14289. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14290. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14291. {
  14292. sstr[c] = loc[strlen("value")+3+c];
  14293. c++;
  14294. }
  14295. sstr[c] = '\0';
  14296. strcpy(valuestr,sstr);
  14297. }
  14298. // DEBUG_INFO("keystr=%s\n",keystr);
  14299. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14300. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14301. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14302. {
  14303. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14306. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14307. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14308. }
  14309. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14310. {
  14311. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14314. }
  14315. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14316. {
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14319. }
  14320. if(strcmp(keystr, "BlinkRepeat") == 0)
  14321. {
  14322. //Charger.BlinkRepeat = Integer.parseInt(value);
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14324. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14325. }
  14326. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14327. {
  14328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14330. }
  14331. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14332. {
  14333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14335. }
  14336. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14337. {
  14338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14340. }
  14341. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14342. {
  14343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14345. HeartBeatWaitTime = atoi(valuestr);
  14346. }
  14347. if(strcmp(keystr, "LightIntensity") == 0)
  14348. {
  14349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14350. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14351. }
  14352. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14353. {
  14354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14356. }
  14357. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14358. {
  14359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14361. }
  14362. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14363. {
  14364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14366. }
  14367. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14368. {
  14369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14371. }
  14372. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14373. {
  14374. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14376. }
  14377. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14378. {
  14379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14381. }
  14382. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14383. {
  14384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14386. }
  14387. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14388. {
  14389. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14391. }
  14392. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14393. {
  14394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14396. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14397. }
  14398. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14399. {
  14400. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14401. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14402. }
  14403. if(strcmp(keystr, "ResetRetries") == 0)
  14404. {
  14405. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14407. }
  14408. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14409. {
  14410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14412. }
  14413. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14414. {
  14415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14417. }
  14418. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14419. {
  14420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14421. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14422. }
  14423. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14424. {
  14425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14427. }
  14428. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14429. {
  14430. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14432. }
  14433. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14434. {
  14435. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14436. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14437. }
  14438. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14439. {
  14440. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14442. }
  14443. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14444. {
  14445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14446. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14447. }
  14448. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14449. {
  14450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14451. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14452. }
  14453. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14454. {
  14455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14456. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14457. }
  14458. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14459. {
  14460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14462. TransactionMessageAttemptsValue = atoi(valuestr);
  14463. }
  14464. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14465. {
  14466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14468. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14469. }
  14470. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14471. {
  14472. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14474. }
  14475. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14476. {
  14477. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14479. }
  14480. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14481. {
  14482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14484. }
  14485. if(strcmp(keystr, "AuthorizationKey") == 0)
  14486. {
  14487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14488. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14490. }
  14491. if(strcmp(keystr, "SecurityProfile") == 0)
  14492. {
  14493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14494. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14496. }
  14497. if(strcmp(keystr, "DefaultPrice") == 0)
  14498. {
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14501. }
  14502. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14503. {
  14504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14506. }
  14507. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14508. {
  14509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14511. }
  14512. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14513. {
  14514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14516. }
  14517. if(strcmp(keystr, "FreeVend") == 0)
  14518. {
  14519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14521. }
  14522. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14523. {
  14524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14526. }
  14527. if(strcmp(keystr, "OcppServer") == 0)
  14528. {
  14529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14530. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14531. }
  14532. if(strcmp(keystr, "MaintainServer") == 0)
  14533. {
  14534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14535. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14536. }
  14537. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14538. {
  14539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14541. }
  14542. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14543. {
  14544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14546. }
  14547. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14548. {
  14549. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14551. }
  14552. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14553. {
  14554. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14555. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14556. }
  14557. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14558. {
  14559. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14560. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14561. }
  14562. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14563. {
  14564. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14566. }
  14567. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14568. {
  14569. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14571. }
  14572. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14573. {
  14574. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14576. }
  14577. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14578. {
  14579. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14581. }
  14582. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14583. {
  14584. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14586. }
  14587. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14588. {
  14589. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14591. }
  14592. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14593. {
  14594. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14596. }
  14597. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14598. {
  14599. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14601. }
  14602. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14603. {
  14604. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14606. }
  14607. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14608. {
  14609. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14611. }
  14612. }
  14613. }
  14614. fclose(fp);
  14615. }
  14616. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14617. {
  14618. return PASS;
  14619. }
  14620. else
  14621. {
  14622. return FAIL;
  14623. }
  14624. }
  14625. void StoreConfigurationTable(void)
  14626. {
  14627. FILE *outfile;
  14628. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14629. if(outfile == NULL)
  14630. {
  14631. DEBUG_INFO("Error opening file");
  14632. return ;
  14633. }
  14634. /*Core Profile*/
  14635. //AllowOfflineTxForUnknownId
  14636. /*
  14637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14638. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14641. */
  14642. //DEBUG_INFO("data=%s\n",data);
  14643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14644. //AuthorizationCacheEnabled
  14645. /*
  14646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14649. */
  14650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14651. //AuthorizeRemoteTxRequests
  14652. /*
  14653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14656. */
  14657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14658. //BlinkRepeat
  14659. /*
  14660. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14663. */
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14665. //ClockAlignedDataInterval
  14666. /*
  14667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14670. */
  14671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14672. //ConnectionTimeOut
  14673. /*
  14674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14677. */
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14679. //GetConfigurationMaxKeys
  14680. /*
  14681. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14682. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14684. */
  14685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14686. // HeartbeatInterval
  14687. /*
  14688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14691. */
  14692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14693. // LightIntensity
  14694. /*
  14695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14698. */
  14699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14700. // LocalAuthorizeOffline
  14701. /*
  14702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14705. */
  14706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14707. // LocalPreAuthorize
  14708. /*
  14709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14712. */
  14713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14714. // MaxEnergyOnInvalidId
  14715. /*
  14716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14719. */
  14720. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14722. // MeterValuesAlignedData
  14723. /*
  14724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14727. */
  14728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14729. // MeterValuesAlignedDataMaxLength
  14730. /*
  14731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14732. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14734. */
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14736. // MeterValuesSampledData
  14737. /*
  14738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14741. */
  14742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14743. // MeterValuesSampledDataMaxLength
  14744. /*
  14745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14748. */
  14749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14750. // MeterValueSampleInterval
  14751. /*
  14752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14755. */
  14756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14757. // MinimumStatusDuration
  14758. /*
  14759. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14760. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14762. */
  14763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14764. // NumberOfConnectors
  14765. /*
  14766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14769. {
  14770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14771. }
  14772. else
  14773. {
  14774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14775. }
  14776. */
  14777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14778. // ResetRetries
  14779. /*
  14780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14783. */
  14784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14785. // ConnectorPhaseRotation
  14786. /*
  14787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14790. */
  14791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14792. // ConnectorPhaseRotationMaxLength
  14793. /*
  14794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14797. */
  14798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14799. // StopTransactionOnEVSideDisconnect
  14800. /*
  14801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14804. */
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14806. // StopTransactionOnInvalidId
  14807. /*
  14808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14811. */
  14812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14813. // StopTxnAlignedData
  14814. /*
  14815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14818. */
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14820. // StopTxnAlignedDataMaxLength
  14821. /*
  14822. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14825. */
  14826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14827. // StopTxnSampledData
  14828. /*
  14829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14832. */
  14833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14834. // StopTxnSampledDataMaxLength
  14835. /*
  14836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14839. */
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14841. // SupportedFeatureProfiles
  14842. /*
  14843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14846. */
  14847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14848. // SupportedFeatureProfilesMaxLength
  14849. /*
  14850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14853. */
  14854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14855. // TransactionMessageAttempts
  14856. /*
  14857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14862. // TransactionMessageRetryInterval
  14863. /*
  14864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14869. // UnlockConnectorOnEVSideDisconnect
  14870. /*
  14871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14876. // WebSocketPingInterval
  14877. /*
  14878. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14881. */
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14883. // QueueOffLineMeterValues
  14884. /*
  14885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14888. */
  14889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14890. // AuthorizationKey
  14891. /*
  14892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14895. */
  14896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14897. // SecurityProfile
  14898. /*
  14899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14902. */
  14903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14904. // DefaultPrice
  14905. /*
  14906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14909. */
  14910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14911. // CustomDisplayCostAndPrice
  14912. /*
  14913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14916. */
  14917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14918. // CustomIdleFeeAfterStop
  14919. /*
  14920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14923. */
  14924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14925. // SystemUptimeSec
  14926. /*
  14927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14930. */
  14931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14932. // FreeVend
  14933. /*
  14934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14937. */
  14938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14939. // FreeVendIdtag
  14940. /*
  14941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14944. */
  14945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14946. // OcppServer
  14947. /*
  14948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14951. */
  14952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14953. // MaintainServer
  14954. /*
  14955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14958. */
  14959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14960. // StatusNotificationPeriodically
  14961. /*
  14962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14965. */
  14966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14967. // StatusNotificationInterval
  14968. /*
  14969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14972. */
  14973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14974. // isEnableLocalPowerSharing
  14975. /*
  14976. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14979. */
  14980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14981. // PowerSharingServerIP
  14982. /*
  14983. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14986. */
  14987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14988. // EVCCID_PREFIX
  14989. /*
  14990. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14993. */
  14994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14995. // ConfigurationVersion
  14996. /*
  14997. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15000. */
  15001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15002. //* Local Auth List Management Profile*/
  15003. //LocalAuthListEnabled
  15004. /*
  15005. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15008. */
  15009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15010. //LocalAuthListMaxLength
  15011. /*
  15012. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15015. */
  15016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15017. //SendLocalListMaxLength
  15018. /*
  15019. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15022. */
  15023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15024. //ReserveConnectorZeroSupported
  15025. /*
  15026. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15029. */
  15030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15031. //* Smart Charging Profile */
  15032. //ChargeProfileMaxStackLevel
  15033. /*
  15034. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15037. */
  15038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15039. // ChargingScheduleAllowedChargingRateUnit
  15040. /*
  15041. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15044. */
  15045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15046. // ChargingScheduleMaxPeriods
  15047. /*
  15048. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15051. */
  15052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15053. // ConnectorSwitch3to1PhaseSupported
  15054. /*
  15055. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15058. */
  15059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15060. // MaxChargingProfilesInstalled
  15061. /*
  15062. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15065. */
  15066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15067. fclose(outfile);
  15068. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15069. }
  15070. void getKeyValue(char *keyReq)
  15071. {
  15072. int isEmpty = FALSE;
  15073. int isKnowKey = FALSE;
  15074. DEBUG_INFO("keyReq = %s\n", keyReq);
  15075. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15076. isEmpty = TRUE;
  15077. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15084. }
  15085. else
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15088. }
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15090. isKnowKey = TRUE;
  15091. }
  15092. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15099. }
  15100. else
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15103. }
  15104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15105. isKnowKey = TRUE;
  15106. }
  15107. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15111. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15114. }
  15115. else
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15118. }
  15119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15120. isKnowKey = TRUE;
  15121. }
  15122. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15126. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15129. }
  15130. else
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15133. }
  15134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15135. isKnowKey = TRUE;
  15136. }
  15137. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15141. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15144. }
  15145. else
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15148. }
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15150. isKnowKey = TRUE;
  15151. }
  15152. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15156. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15159. }
  15160. else
  15161. {
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15163. }
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15165. isKnowKey = TRUE;
  15166. }
  15167. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15171. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15174. }
  15175. else
  15176. {
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15178. }
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15180. isKnowKey = TRUE;
  15181. }
  15182. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15189. }
  15190. else
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15193. }
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15195. isKnowKey = TRUE;
  15196. }
  15197. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15201. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15204. }
  15205. else
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15208. }
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15210. isKnowKey = TRUE;
  15211. }
  15212. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15216. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15219. }
  15220. else
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15223. }
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15225. isKnowKey = TRUE;
  15226. }
  15227. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15228. {
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15232. {
  15233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15234. }
  15235. else
  15236. {
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15238. }
  15239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15240. isKnowKey = TRUE;
  15241. }
  15242. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15246. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15247. {
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15249. }
  15250. else
  15251. {
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15253. }
  15254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15255. isKnowKey = TRUE;
  15256. }
  15257. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15261. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15262. {
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15264. }
  15265. else
  15266. {
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15268. }
  15269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15270. isKnowKey = TRUE;
  15271. }
  15272. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15276. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15277. {
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15279. }
  15280. else
  15281. {
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15283. }
  15284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15285. isKnowKey = TRUE;
  15286. }
  15287. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15291. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15292. {
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15294. }
  15295. else
  15296. {
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15298. }
  15299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15300. isKnowKey = TRUE;
  15301. }
  15302. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15303. {
  15304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15306. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15307. {
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15309. }
  15310. else
  15311. {
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15313. }
  15314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15315. isKnowKey = TRUE;
  15316. }
  15317. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15318. {
  15319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15321. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15322. {
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15324. }
  15325. else
  15326. {
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15328. }
  15329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15330. isKnowKey = TRUE;
  15331. }
  15332. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15333. {
  15334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15337. {
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15339. }
  15340. else
  15341. {
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15343. }
  15344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15345. isKnowKey = TRUE;
  15346. }
  15347. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15348. {
  15349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15351. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15352. {
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15354. }
  15355. else
  15356. {
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15358. }
  15359. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15361. isKnowKey = TRUE;
  15362. }
  15363. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15364. {
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15367. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15368. {
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15370. }
  15371. else
  15372. {
  15373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15374. }
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15376. isKnowKey = TRUE;
  15377. }
  15378. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15379. {
  15380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15382. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15383. {
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15385. }
  15386. else
  15387. {
  15388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15389. }
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15391. isKnowKey = TRUE;
  15392. }
  15393. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15394. {
  15395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15398. {
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15400. }
  15401. else
  15402. {
  15403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15404. }
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15406. isKnowKey = TRUE;
  15407. }
  15408. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15409. {
  15410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15412. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15413. {
  15414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15415. }
  15416. else
  15417. {
  15418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15419. }
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15421. isKnowKey = TRUE;
  15422. }
  15423. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15424. {
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15427. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15428. {
  15429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15430. }
  15431. else
  15432. {
  15433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15434. }
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15436. isKnowKey = TRUE;
  15437. }
  15438. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15439. {
  15440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15443. {
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15445. }
  15446. else
  15447. {
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15449. }
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15451. isKnowKey = TRUE;
  15452. }
  15453. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15454. {
  15455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15457. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15458. {
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15460. }
  15461. else
  15462. {
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15464. }
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15466. isKnowKey = TRUE;
  15467. }
  15468. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15469. {
  15470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15472. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15473. {
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15475. }
  15476. else
  15477. {
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15479. }
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15481. isKnowKey = TRUE;
  15482. }
  15483. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15484. {
  15485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15487. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15488. {
  15489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15490. }
  15491. else
  15492. {
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15494. }
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15496. isKnowKey = TRUE;
  15497. }
  15498. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15499. {
  15500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15502. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15503. {
  15504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15505. }
  15506. else
  15507. {
  15508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15509. }
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15511. isKnowKey = TRUE;
  15512. }
  15513. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15514. {
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15517. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15518. {
  15519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15520. }
  15521. else
  15522. {
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15524. }
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15526. isKnowKey = TRUE;
  15527. }
  15528. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15529. {
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15532. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15533. {
  15534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15535. }
  15536. else
  15537. {
  15538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15539. }
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15541. isKnowKey = TRUE;
  15542. }
  15543. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15547. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15548. {
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15550. }
  15551. else
  15552. {
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15554. }
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15556. isKnowKey = TRUE;
  15557. }
  15558. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15563. {
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15565. }
  15566. else
  15567. {
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15569. }
  15570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15571. isKnowKey = TRUE;
  15572. }
  15573. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15574. {
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15577. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15578. {
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15580. }
  15581. else
  15582. {
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15584. }
  15585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15586. isKnowKey = TRUE;
  15587. }
  15588. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15589. {
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15592. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15593. {
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15595. }
  15596. else
  15597. {
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15599. }
  15600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15601. isKnowKey = TRUE;
  15602. }
  15603. /*
  15604. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15605. {
  15606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15608. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15609. {
  15610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15611. }
  15612. else
  15613. {
  15614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15615. }
  15616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15617. isKnowKey = TRUE;
  15618. }*/
  15619. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15620. {
  15621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15623. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15624. {
  15625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15626. }
  15627. else
  15628. {
  15629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15630. }
  15631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15632. isKnowKey = TRUE;
  15633. }
  15634. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15635. {
  15636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15639. {
  15640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15641. }
  15642. else
  15643. {
  15644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15645. }
  15646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15647. isKnowKey = TRUE;
  15648. }
  15649. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15650. {
  15651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15653. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15654. {
  15655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15656. }
  15657. else
  15658. {
  15659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15660. }
  15661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15662. isKnowKey = TRUE;
  15663. }
  15664. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15665. {
  15666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15669. {
  15670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15671. }
  15672. else
  15673. {
  15674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15675. }
  15676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15677. isKnowKey = TRUE;
  15678. }
  15679. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15680. {
  15681. struct sysinfo s_info;
  15682. int error = sysinfo(&s_info);
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15686. {
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15688. }
  15689. else
  15690. {
  15691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15692. }
  15693. if(error != 0)
  15694. {
  15695. DEBUG_WARN("System uptime get error: %d\n", error);
  15696. }
  15697. else
  15698. {
  15699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15700. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15701. }
  15702. isKnowKey = TRUE;
  15703. }
  15704. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15705. {
  15706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15708. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15709. {
  15710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15711. }
  15712. else
  15713. {
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15715. }
  15716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15717. isKnowKey = TRUE;
  15718. }
  15719. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15720. {
  15721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15723. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15724. {
  15725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15726. }
  15727. else
  15728. {
  15729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15730. }
  15731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15732. isKnowKey = TRUE;
  15733. }
  15734. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15735. {
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15738. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15739. {
  15740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15741. }
  15742. else
  15743. {
  15744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15745. }
  15746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15747. isKnowKey = TRUE;
  15748. }
  15749. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15750. {
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15753. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15754. {
  15755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15756. }
  15757. else
  15758. {
  15759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15760. }
  15761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15762. isKnowKey = TRUE;
  15763. }
  15764. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15765. {
  15766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15768. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15769. {
  15770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15771. }
  15772. else
  15773. {
  15774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15775. }
  15776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15777. isKnowKey = TRUE;
  15778. }
  15779. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15780. {
  15781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15783. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15784. {
  15785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15786. }
  15787. else
  15788. {
  15789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15790. }
  15791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15792. isKnowKey = TRUE;
  15793. }
  15794. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15795. {
  15796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15799. {
  15800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15801. }
  15802. else
  15803. {
  15804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15805. }
  15806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15807. isKnowKey = TRUE;
  15808. }
  15809. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15810. {
  15811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15814. {
  15815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15816. }
  15817. else
  15818. {
  15819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15820. }
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15822. isKnowKey = TRUE;
  15823. }
  15824. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15825. {
  15826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15829. {
  15830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15831. }
  15832. else
  15833. {
  15834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15835. }
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15837. isKnowKey = TRUE;
  15838. }
  15839. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15840. {
  15841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15844. {
  15845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15846. }
  15847. else
  15848. {
  15849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15850. }
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15852. isKnowKey = TRUE;
  15853. }
  15854. #if 1
  15855. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15856. {
  15857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15859. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15860. {
  15861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15862. }
  15863. else
  15864. {
  15865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15866. }
  15867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15868. isKnowKey = TRUE;
  15869. }
  15870. #endif
  15871. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15872. {
  15873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15875. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15876. {
  15877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15878. }
  15879. else
  15880. {
  15881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15882. }
  15883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15884. isKnowKey = TRUE;
  15885. }
  15886. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15887. {
  15888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15890. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15891. {
  15892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15893. }
  15894. else
  15895. {
  15896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15897. }
  15898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15899. isKnowKey = TRUE;
  15900. }
  15901. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15902. {
  15903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15905. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15906. {
  15907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15908. }
  15909. else
  15910. {
  15911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15912. }
  15913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15914. isKnowKey = TRUE;
  15915. }
  15916. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15917. {
  15918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15920. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15921. {
  15922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15923. }
  15924. else
  15925. {
  15926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15927. }
  15928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15929. isKnowKey = TRUE;
  15930. }
  15931. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15932. {
  15933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15935. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15936. {
  15937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15938. }
  15939. else
  15940. {
  15941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15942. }
  15943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15944. isKnowKey = TRUE;
  15945. }
  15946. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15947. {
  15948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15950. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15951. {
  15952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15953. }
  15954. else
  15955. {
  15956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15957. }
  15958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15959. isKnowKey = TRUE;
  15960. }
  15961. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15962. {
  15963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15965. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15966. {
  15967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15968. }
  15969. else
  15970. {
  15971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15972. }
  15973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15974. isKnowKey = TRUE;
  15975. }
  15976. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15977. {
  15978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15980. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15981. {
  15982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15983. }
  15984. else
  15985. {
  15986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15987. }
  15988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15989. isKnowKey = TRUE;
  15990. }
  15991. //=========================================================
  15992. if(!isEmpty && !isKnowKey)
  15993. {
  15994. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15995. strcpy(unknownkey[UnknownKeynum], keyReq);
  15996. UnknownKeynum = UnknownKeynum + 1;
  15997. }
  15998. }
  15999. void processUnkownKey(void)
  16000. {
  16001. DEBUG_INFO("processUnkownKey...\n");
  16002. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16003. for(int index=0; index < UnknownKeynum; index++)
  16004. {
  16005. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16006. {
  16007. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16008. }
  16009. }
  16010. }
  16011. int setKeyValue(char *key, char *value)
  16012. {
  16013. int isSuccess = NotSupported;
  16014. int check_ascii=0;
  16015. char str[501]={0};
  16016. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16017. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16018. {
  16019. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16020. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16021. {
  16022. strcpy(str, (const char*)value);
  16023. for(int i = 0; str[i]; i++){
  16024. str[i] = tolower(str[i]);
  16025. }
  16026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. else
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. }
  16034. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16035. {
  16036. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16037. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16038. {
  16039. strcpy(str, (const char*)value);
  16040. for(int i = 0; str[i]; i++){
  16041. str[i] = tolower(str[i]);
  16042. }
  16043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16046. }
  16047. else
  16048. {
  16049. isSuccess = ConfigurationStatus_Rejected;
  16050. }
  16051. }
  16052. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16053. {
  16054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16055. {
  16056. strcpy(str, (const char*)value);
  16057. for(int i = 0; str[i]; i++)
  16058. {
  16059. str[i] = tolower(str[i]);
  16060. }
  16061. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16063. isSuccess = ConfigurationStatus_Accepted;
  16064. }
  16065. else
  16066. {
  16067. isSuccess = ConfigurationStatus_Rejected;
  16068. }
  16069. }
  16070. if(strcmp(key, "BlinkRepeat") == 0)
  16071. {
  16072. //Charger.BlinkRepeat = Integer.parseInt(value);
  16073. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16074. {
  16075. check_ascii = value[0];
  16076. if( (check_ascii < 48) || (check_ascii > 57) )
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. else
  16081. {
  16082. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16083. isSuccess = ConfigurationStatus_Accepted;
  16084. }
  16085. }
  16086. else
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. }
  16091. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16092. {
  16093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16094. {
  16095. check_ascii = value[0];
  16096. if( (check_ascii < 48) || (check_ascii > 57) )
  16097. {
  16098. isSuccess = ConfigurationStatus_Rejected;
  16099. }
  16100. else
  16101. {
  16102. if((atoi(value) == 0) || (atoi(value) >= 5))
  16103. {
  16104. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16105. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16106. isSuccess = ConfigurationStatus_Accepted;
  16107. }
  16108. else
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. }
  16112. else
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. }
  16117. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16118. {
  16119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16120. {
  16121. check_ascii = value[0];
  16122. if( (check_ascii < 48) || (check_ascii > 57) )
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. else
  16127. {
  16128. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16129. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16130. isSuccess = ConfigurationStatus_Accepted;
  16131. }
  16132. }
  16133. else
  16134. {
  16135. isSuccess = ConfigurationStatus_Rejected;
  16136. }
  16137. }
  16138. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16139. {
  16140. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16141. {
  16142. check_ascii = value[0];
  16143. if( (check_ascii < 48) || (check_ascii > 57) )
  16144. {
  16145. isSuccess = ConfigurationStatus_Rejected;
  16146. }
  16147. else
  16148. {
  16149. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16151. isSuccess = ConfigurationStatus_Accepted;
  16152. }
  16153. }
  16154. else
  16155. {
  16156. isSuccess = ConfigurationStatus_Rejected;
  16157. }
  16158. }
  16159. if(strcmp(key, "HeartbeatInterval") == 0)
  16160. {
  16161. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16162. {
  16163. check_ascii = value[0];
  16164. if( (check_ascii < 48) || (check_ascii > 57) )
  16165. {
  16166. isSuccess = ConfigurationStatus_Rejected;
  16167. }
  16168. else
  16169. {
  16170. if((atoi(value) == 0) || (atoi(value) >= 10))
  16171. {
  16172. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16174. HeartBeatWaitTime = atoi(value);
  16175. isSuccess = ConfigurationStatus_Accepted;
  16176. }
  16177. else
  16178. {
  16179. isSuccess = ConfigurationStatus_Rejected;
  16180. }
  16181. }
  16182. }
  16183. else
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. }
  16188. if(strcmp(key, "LightIntensity") == 0)
  16189. {
  16190. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16191. {
  16192. check_ascii = value[0];
  16193. if( (check_ascii < 48) || (check_ascii > 57) )
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. else
  16198. {
  16199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16200. isSuccess = ConfigurationStatus_Accepted;
  16201. }
  16202. }
  16203. else
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. }
  16208. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16209. {
  16210. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16211. {
  16212. strcpy(str, (const char*)value);
  16213. for(int i = 0; str[i]; i++)
  16214. {
  16215. str[i] = tolower(str[i]);
  16216. }
  16217. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16218. isSuccess = ConfigurationStatus_Accepted;
  16219. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16220. }
  16221. else
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. }
  16226. if(strcmp(key, "LocalPreAuthorize") == 0)
  16227. {
  16228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16229. {
  16230. strcpy(str, (const char*)value);
  16231. for(int i = 0; str[i]; i++)
  16232. {
  16233. str[i] = tolower(str[i]);
  16234. }
  16235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16236. isSuccess = ConfigurationStatus_Accepted;
  16237. }
  16238. else
  16239. {
  16240. isSuccess = ConfigurationStatus_Rejected;
  16241. }
  16242. }
  16243. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16244. {
  16245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16246. {
  16247. check_ascii = value[0];
  16248. if( (check_ascii < 48) || (check_ascii > 57) )
  16249. {
  16250. isSuccess = ConfigurationStatus_Rejected;
  16251. }
  16252. else
  16253. {
  16254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16255. isSuccess = ConfigurationStatus_Accepted;
  16256. }
  16257. }
  16258. else
  16259. {
  16260. isSuccess = ConfigurationStatus_Rejected;
  16261. }
  16262. }
  16263. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16264. {
  16265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16266. {
  16267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16268. isSuccess = ConfigurationStatus_Accepted;
  16269. }
  16270. else
  16271. {
  16272. isSuccess = ConfigurationStatus_Rejected;
  16273. }
  16274. }
  16275. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16276. {
  16277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16278. {
  16279. check_ascii = value[0];
  16280. if( (check_ascii < 48) || (check_ascii > 57) )
  16281. {
  16282. isSuccess = ConfigurationStatus_Rejected;
  16283. }
  16284. else
  16285. {
  16286. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16288. isSuccess = ConfigurationStatus_Accepted;
  16289. }
  16290. }
  16291. else
  16292. {
  16293. isSuccess = ConfigurationStatus_Rejected;
  16294. }
  16295. }
  16296. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16297. {
  16298. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16299. {
  16300. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16301. isSuccess = ConfigurationStatus_Accepted;
  16302. }
  16303. else
  16304. {
  16305. isSuccess = ConfigurationStatus_Rejected;
  16306. }
  16307. }
  16308. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16309. {
  16310. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16311. {
  16312. check_ascii = value[0];
  16313. if( (check_ascii < 48) || (check_ascii > 57) )
  16314. {
  16315. isSuccess = ConfigurationStatus_Rejected;
  16316. }
  16317. else
  16318. {
  16319. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16321. isSuccess = ConfigurationStatus_Accepted;
  16322. }
  16323. }
  16324. else
  16325. {
  16326. isSuccess = ConfigurationStatus_Rejected;
  16327. }
  16328. }
  16329. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16330. {
  16331. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16332. {
  16333. check_ascii = value[0];
  16334. if( (check_ascii < 48) || (check_ascii > 57) )
  16335. {
  16336. isSuccess = ConfigurationStatus_Rejected;
  16337. }
  16338. else
  16339. {
  16340. if((atoi(value) == 0) || (atoi(value) >= 3))
  16341. {
  16342. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16344. isSuccess = ConfigurationStatus_Accepted;
  16345. }
  16346. else
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. }
  16351. }
  16352. else
  16353. {
  16354. isSuccess = ConfigurationStatus_Rejected;
  16355. }
  16356. }
  16357. if(strcmp(key, "MinimumStatusDuration") == 0)
  16358. {
  16359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16360. {
  16361. check_ascii = value[0];
  16362. if( (check_ascii < 48) || (check_ascii > 57) )
  16363. {
  16364. isSuccess = ConfigurationStatus_Rejected;
  16365. }
  16366. else
  16367. {
  16368. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16369. {
  16370. isSuccess = ConfigurationStatus_Rejected;
  16371. }
  16372. else
  16373. {
  16374. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16376. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16377. isSuccess = ConfigurationStatus_Accepted;
  16378. }
  16379. }
  16380. }
  16381. else
  16382. {
  16383. isSuccess = ConfigurationStatus_Rejected;
  16384. }
  16385. }
  16386. if(strcmp(key, "NumberOfConnectors") == 0)
  16387. {
  16388. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16389. {
  16390. check_ascii = value[0];
  16391. if( (check_ascii < 48) || (check_ascii > 57) )
  16392. {
  16393. isSuccess = ConfigurationStatus_Rejected;
  16394. }
  16395. else
  16396. {
  16397. //Charger.ResetRetries = Integer.parseInt(value);
  16398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16399. isSuccess = ConfigurationStatus_Accepted;
  16400. }
  16401. }
  16402. else
  16403. {
  16404. isSuccess = ConfigurationStatus_Rejected;
  16405. }
  16406. }
  16407. if(strcmp(key, "ResetRetries") == 0)
  16408. {
  16409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16410. {
  16411. check_ascii = value[0];
  16412. if( (check_ascii < 48) || (check_ascii > 57) )
  16413. {
  16414. isSuccess = ConfigurationStatus_Rejected;
  16415. }
  16416. else
  16417. {
  16418. //Charger.ResetRetries = Integer.parseInt(value);
  16419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16420. isSuccess = ConfigurationStatus_Accepted;
  16421. }
  16422. }
  16423. else
  16424. {
  16425. isSuccess = ConfigurationStatus_Rejected;
  16426. }
  16427. }
  16428. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16429. {
  16430. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16431. {
  16432. strcpy(str, (const char*)value);
  16433. for(int i = 0; str[i]; i++)
  16434. {
  16435. str[i] = tolower(str[i]);
  16436. }
  16437. if(strcmp(str, "notapplicable")== 0)
  16438. {
  16439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16440. isSuccess = ConfigurationStatus_Accepted;
  16441. }
  16442. else if(strcmp(str, "unknown")== 0)
  16443. {
  16444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16445. isSuccess = ConfigurationStatus_Accepted;
  16446. }
  16447. else if(strcmp(str, "rst")== 0)
  16448. {
  16449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16450. isSuccess = ConfigurationStatus_Accepted;
  16451. }
  16452. else if(strcmp(str, "rts")== 0)
  16453. {
  16454. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16455. isSuccess = ConfigurationStatus_Accepted;
  16456. }
  16457. else if(strcmp(str, "srt")== 0)
  16458. {
  16459. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16460. isSuccess = ConfigurationStatus_Accepted;
  16461. }
  16462. else if(strcmp(str, "str")== 0)
  16463. {
  16464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. else if(strcmp(str, "trs")== 0)
  16468. {
  16469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16470. isSuccess = ConfigurationStatus_Accepted;
  16471. }
  16472. else if(strcmp(str, "tsr")== 0)
  16473. {
  16474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16475. isSuccess = ConfigurationStatus_Accepted;
  16476. }
  16477. else
  16478. {
  16479. isSuccess = ConfigurationStatus_Rejected;
  16480. }
  16481. }
  16482. else
  16483. {
  16484. isSuccess = ConfigurationStatus_Rejected;
  16485. }
  16486. }
  16487. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16488. {
  16489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16490. {
  16491. check_ascii = value[0];
  16492. if( (check_ascii < 48) || (check_ascii > 57) )
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. else
  16497. {
  16498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16499. isSuccess = ConfigurationStatus_Accepted;
  16500. }
  16501. }
  16502. else
  16503. {
  16504. isSuccess = ConfigurationStatus_Rejected;
  16505. }
  16506. }
  16507. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16508. {
  16509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16510. {
  16511. strcpy(str, (const char*)value);
  16512. for(int i = 0; str[i]; i++)
  16513. {
  16514. str[i] = tolower(str[i]);
  16515. }
  16516. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16518. isSuccess = ConfigurationStatus_Accepted;
  16519. }
  16520. else
  16521. {
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. }
  16525. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16526. {
  16527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16528. {
  16529. strcpy(str, (const char*)value);
  16530. for(int i = 0; str[i]; i++)
  16531. {
  16532. str[i] = tolower(str[i]);
  16533. }
  16534. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16536. isSuccess = ConfigurationStatus_Accepted;
  16537. }
  16538. else
  16539. {
  16540. isSuccess = ConfigurationStatus_Rejected;
  16541. }
  16542. }
  16543. if(strcmp(key, "StopTxnAlignedData") == 0)
  16544. {
  16545. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16546. {
  16547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16548. isSuccess = ConfigurationStatus_Accepted;
  16549. }
  16550. else
  16551. {
  16552. isSuccess = ConfigurationStatus_Rejected;
  16553. }
  16554. }
  16555. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16556. {
  16557. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16558. {
  16559. check_ascii = value[0];
  16560. if( (check_ascii < 48) || (check_ascii > 57) )
  16561. {
  16562. isSuccess = ConfigurationStatus_Rejected;
  16563. }
  16564. else
  16565. {
  16566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16567. isSuccess = ConfigurationStatus_Accepted;
  16568. }
  16569. }
  16570. else
  16571. {
  16572. isSuccess = ConfigurationStatus_Rejected;
  16573. }
  16574. }
  16575. if(strcmp(key, "StopTxnSampledData") == 0)
  16576. {
  16577. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16578. {
  16579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16580. isSuccess = ConfigurationStatus_Accepted;
  16581. }
  16582. else
  16583. {
  16584. isSuccess = ConfigurationStatus_Rejected;
  16585. }
  16586. }
  16587. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16588. {
  16589. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16590. {
  16591. check_ascii = value[0];
  16592. if( (check_ascii < 48) || (check_ascii > 57) )
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. else
  16597. {
  16598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16599. isSuccess = ConfigurationStatus_Accepted;
  16600. }
  16601. }
  16602. else
  16603. {
  16604. isSuccess = ConfigurationStatus_Rejected;
  16605. }
  16606. }
  16607. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16608. {
  16609. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16610. {
  16611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16612. isSuccess = ConfigurationStatus_Accepted;
  16613. }
  16614. else
  16615. {
  16616. isSuccess = ConfigurationStatus_Rejected;
  16617. }
  16618. }
  16619. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16620. {
  16621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16622. {
  16623. check_ascii = value[0];
  16624. if( (check_ascii < 48) || (check_ascii > 57) )
  16625. {
  16626. isSuccess = ConfigurationStatus_Rejected;
  16627. }
  16628. else
  16629. {
  16630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16631. isSuccess = ConfigurationStatus_Accepted;
  16632. }
  16633. }
  16634. else
  16635. {
  16636. isSuccess = ConfigurationStatus_Rejected;
  16637. }
  16638. }
  16639. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16640. {
  16641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16642. {
  16643. check_ascii = value[0];
  16644. if( (check_ascii < 48) || (check_ascii > 57) )
  16645. {
  16646. isSuccess = ConfigurationStatus_Rejected;
  16647. }
  16648. else
  16649. {
  16650. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16651. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16652. TransactionMessageAttemptsValue = atoi(value);
  16653. isSuccess = ConfigurationStatus_Accepted;
  16654. }
  16655. }
  16656. else
  16657. {
  16658. isSuccess = ConfigurationStatus_Rejected;
  16659. }
  16660. }
  16661. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16662. {
  16663. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16664. {
  16665. check_ascii = value[0];
  16666. if( (check_ascii < 48) || (check_ascii > 57) )
  16667. {
  16668. isSuccess = ConfigurationStatus_Rejected;
  16669. }
  16670. else
  16671. {
  16672. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16674. TransactionMessageRetryIntervalValue = atoi(value);
  16675. isSuccess = ConfigurationStatus_Accepted;
  16676. }
  16677. }
  16678. else
  16679. {
  16680. isSuccess = ConfigurationStatus_Rejected;
  16681. }
  16682. }
  16683. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16684. {
  16685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16686. {
  16687. strcpy(str, (const char*)value);
  16688. for(int i = 0; str[i]; i++)
  16689. {
  16690. str[i] = tolower(str[i]);
  16691. }
  16692. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16694. isSuccess = ConfigurationStatus_Accepted;
  16695. }
  16696. else
  16697. {
  16698. isSuccess = ConfigurationStatus_Rejected;
  16699. }
  16700. }
  16701. if(strcmp(key, "WebSocketPingInterval") == 0)
  16702. {
  16703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16704. {
  16705. check_ascii = value[0];
  16706. if( (check_ascii < 48) || (check_ascii > 57) )
  16707. {
  16708. isSuccess = ConfigurationStatus_Rejected;
  16709. }
  16710. else
  16711. {
  16712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16713. isSuccess = ConfigurationStatus_Accepted;
  16714. if((atoi(value) == 0) || (atoi(value) >= 10))
  16715. {
  16716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16717. isSuccess = ConfigurationStatus_Accepted;
  16718. }
  16719. else
  16720. isSuccess = ConfigurationStatus_Rejected;
  16721. }
  16722. }
  16723. else
  16724. {
  16725. isSuccess = ConfigurationStatus_Rejected;
  16726. }
  16727. }
  16728. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16729. {
  16730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16731. {
  16732. strcpy(str, (const char*)value);
  16733. for(int i = 0; str[i]; i++)
  16734. {
  16735. str[i] = tolower(str[i]);
  16736. }
  16737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16738. isSuccess = ConfigurationStatus_Accepted;
  16739. }
  16740. else
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. }
  16745. if(strcmp(key, "AuthorizationKey") == 0)
  16746. {
  16747. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16748. {
  16749. strcpy(str, (const char*)value);
  16750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16751. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16752. isSuccess = ConfigurationStatus_Accepted;
  16753. }
  16754. else
  16755. {
  16756. isSuccess = ConfigurationStatus_Rejected;
  16757. }
  16758. }
  16759. if(strcmp(key, "SecurityProfile") == 0)
  16760. {
  16761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16762. {
  16763. check_ascii = value[0];
  16764. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. else if(check_ascii == 0x33)
  16769. {
  16770. isSuccess = NotSupported;
  16771. }
  16772. else
  16773. {
  16774. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16775. {
  16776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16777. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16778. isSuccess = ConfigurationStatus_Accepted;
  16779. }
  16780. else
  16781. isSuccess = ConfigurationStatus_Rejected;
  16782. }
  16783. }
  16784. else
  16785. {
  16786. isSuccess = ConfigurationStatus_Rejected;
  16787. }
  16788. }
  16789. if(strcmp(key, "DefaultPrice") == 0)
  16790. {
  16791. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16792. {
  16793. strcpy(str, (const char*)value);
  16794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16795. isSuccess = ConfigurationStatus_Accepted;
  16796. }
  16797. else
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. }
  16802. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16803. {
  16804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16805. {
  16806. strcpy(str, (const char*)value);
  16807. for(int i = 0; str[i]; i++)
  16808. {
  16809. str[i] = tolower(str[i]);
  16810. }
  16811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16812. isSuccess = ConfigurationStatus_Accepted;
  16813. }
  16814. else
  16815. {
  16816. isSuccess = ConfigurationStatus_Rejected;
  16817. }
  16818. }
  16819. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16820. {
  16821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16822. {
  16823. strcpy(str, (const char*)value);
  16824. for(int i = 0; str[i]; i++)
  16825. {
  16826. str[i] = tolower(str[i]);
  16827. }
  16828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16829. isSuccess = ConfigurationStatus_Accepted;
  16830. }
  16831. else
  16832. {
  16833. isSuccess = ConfigurationStatus_Rejected;
  16834. }
  16835. }
  16836. if(strcmp(key, "SystemUptimeSec") == 0)
  16837. {
  16838. isSuccess = NotSupported;
  16839. }
  16840. if(strcmp(key, "FreeVend") == 0)
  16841. {
  16842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16843. {
  16844. strcpy(str, (const char*)value);
  16845. for(int i = 0; str[i]; i++)
  16846. {
  16847. str[i] = tolower(str[i]);
  16848. }
  16849. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16851. isSuccess = ConfigurationStatus_Accepted;
  16852. }
  16853. else
  16854. {
  16855. isSuccess = ConfigurationStatus_Rejected;
  16856. }
  16857. }
  16858. if(strcmp(key, "FreeVendIdtag") == 0)
  16859. {
  16860. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16861. {
  16862. strcpy(str, (const char*)value);
  16863. if(strlen(str) <= 20)
  16864. {
  16865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. else
  16869. {
  16870. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16871. isSuccess = ConfigurationStatus_Rejected;
  16872. }
  16873. }
  16874. else
  16875. {
  16876. isSuccess = ConfigurationStatus_Rejected;
  16877. }
  16878. }
  16879. if(strcmp(key, "OcppServer") == 0)
  16880. {
  16881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16882. {
  16883. strcpy(str, (const char*)value);
  16884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16885. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16886. isSuccess = ConfigurationStatus_Accepted;
  16887. }
  16888. else
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. }
  16893. if(strcmp(key, "MaintainServer") == 0)
  16894. {
  16895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16896. {
  16897. strcpy(str, (const char*)value);
  16898. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16899. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16900. isSuccess = ConfigurationStatus_Accepted;
  16901. }
  16902. else
  16903. {
  16904. isSuccess = ConfigurationStatus_Rejected;
  16905. }
  16906. }
  16907. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16908. {
  16909. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16910. {
  16911. strcpy(str, (const char*)value);
  16912. for(int i = 0; str[i]; i++)
  16913. {
  16914. str[i] = tolower(str[i]);
  16915. }
  16916. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16917. isSuccess = ConfigurationStatus_Accepted;
  16918. }
  16919. else
  16920. {
  16921. isSuccess = ConfigurationStatus_Rejected;
  16922. }
  16923. }
  16924. if(strcmp(key, "StatusNotificationInterval") == 0)
  16925. {
  16926. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16927. {
  16928. check_ascii = value[0];
  16929. if( (check_ascii < 48) || (check_ascii > 57) )
  16930. {
  16931. isSuccess = ConfigurationStatus_Rejected;
  16932. }
  16933. else
  16934. {
  16935. if((atoi(value) == 0) || (atoi(value) >= 10))
  16936. {
  16937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16938. isSuccess = ConfigurationStatus_Accepted;
  16939. }
  16940. else
  16941. isSuccess = ConfigurationStatus_Rejected;
  16942. }
  16943. }
  16944. else
  16945. {
  16946. isSuccess = ConfigurationStatus_Rejected;
  16947. }
  16948. }
  16949. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16950. {
  16951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16952. {
  16953. check_ascii = value[0];
  16954. if( (check_ascii < 48) || (check_ascii > 57) )
  16955. {
  16956. isSuccess = ConfigurationStatus_Rejected;
  16957. }
  16958. else
  16959. {
  16960. if(atoi(value) >= 0)
  16961. {
  16962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16963. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16964. isSuccess = ConfigurationStatus_Accepted;
  16965. }
  16966. else
  16967. isSuccess = ConfigurationStatus_Rejected;
  16968. }
  16969. }
  16970. else
  16971. {
  16972. isSuccess = ConfigurationStatus_Rejected;
  16973. }
  16974. }
  16975. if(strcmp(key, "PowerSharingServerIP") == 0)
  16976. {
  16977. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16978. {
  16979. strcpy(str, (const char*)value);
  16980. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16981. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16982. isSuccess = ConfigurationStatus_Accepted;
  16983. }
  16984. else
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. }
  16989. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16990. {
  16991. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16992. {
  16993. strcpy(str, (const char*)value);
  16994. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16995. isSuccess = ConfigurationStatus_Accepted;
  16996. }
  16997. else
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. }
  17002. #if 0
  17003. //For OCPP Test Case
  17004. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17005. {
  17006. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17007. {
  17008. strcpy(str, (const char*)value);
  17009. for(int i = 0; str[i]; i++)
  17010. {
  17011. str[i] = tolower(str[i]);
  17012. }
  17013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17014. isSuccess = ConfigurationStatus_Accepted;
  17015. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17016. }
  17017. else
  17018. {
  17019. isSuccess = ConfigurationStatus_Rejected;
  17020. }
  17021. }
  17022. #endif
  17023. #if 1
  17024. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17025. {
  17026. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17027. {
  17028. strcpy(str, (const char*)value);
  17029. for(int i = 0; str[i]; i++)
  17030. {
  17031. str[i] = tolower(str[i]);
  17032. }
  17033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17034. isSuccess = ConfigurationStatus_Accepted;
  17035. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17036. }
  17037. else
  17038. {
  17039. isSuccess = ConfigurationStatus_Rejected;
  17040. }
  17041. }
  17042. #endif
  17043. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17044. {
  17045. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17046. {
  17047. check_ascii = value[0];
  17048. if( (check_ascii < 48) || (check_ascii > 57) )
  17049. {
  17050. isSuccess = ConfigurationStatus_Rejected;
  17051. }
  17052. else
  17053. {
  17054. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17055. isSuccess = ConfigurationStatus_Accepted;
  17056. }
  17057. }
  17058. else
  17059. {
  17060. isSuccess = ConfigurationStatus_Rejected;
  17061. }
  17062. }
  17063. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17064. {
  17065. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17066. {
  17067. check_ascii = value[0];
  17068. if( (check_ascii < 48) || (check_ascii > 57) )
  17069. {
  17070. isSuccess = ConfigurationStatus_Rejected;
  17071. }
  17072. else
  17073. {
  17074. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17075. isSuccess = ConfigurationStatus_Accepted;
  17076. }
  17077. }
  17078. else
  17079. {
  17080. isSuccess = ConfigurationStatus_Rejected;
  17081. }
  17082. }
  17083. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17084. {
  17085. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17086. {
  17087. strcpy(str, (const char*)value);
  17088. for(int i = 0; str[i]; i++)
  17089. {
  17090. str[i] = tolower(str[i]);
  17091. }
  17092. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17093. isSuccess = ConfigurationStatus_Accepted;
  17094. }
  17095. else
  17096. {
  17097. isSuccess = ConfigurationStatus_Rejected;
  17098. }
  17099. }
  17100. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17101. {
  17102. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17103. {
  17104. check_ascii = value[0];
  17105. if( (check_ascii < 48) || (check_ascii > 57) )
  17106. {
  17107. isSuccess = ConfigurationStatus_Rejected;
  17108. }
  17109. else
  17110. {
  17111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17112. isSuccess = ConfigurationStatus_Accepted;
  17113. }
  17114. }
  17115. else
  17116. {
  17117. isSuccess = ConfigurationStatus_Rejected;
  17118. }
  17119. }
  17120. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17121. {
  17122. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17123. {
  17124. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17125. isSuccess = ConfigurationStatus_Accepted;
  17126. }
  17127. else
  17128. {
  17129. isSuccess = ConfigurationStatus_Rejected;
  17130. }
  17131. }
  17132. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17133. {
  17134. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17135. {
  17136. check_ascii = value[0];
  17137. if( (check_ascii < 48) || (check_ascii > 57) )
  17138. {
  17139. isSuccess = ConfigurationStatus_Rejected;
  17140. }
  17141. else
  17142. {
  17143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17144. isSuccess = ConfigurationStatus_Accepted;
  17145. }
  17146. }
  17147. else
  17148. {
  17149. isSuccess = ConfigurationStatus_Rejected;
  17150. }
  17151. }
  17152. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17153. {
  17154. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17155. {
  17156. strcpy(str, (const char*)value);
  17157. for(int i = 0; str[i]; i++)
  17158. {
  17159. str[i] = tolower(str[i]);
  17160. }
  17161. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17162. isSuccess = ConfigurationStatus_Accepted;
  17163. }
  17164. else
  17165. {
  17166. isSuccess = ConfigurationStatus_Rejected;
  17167. }
  17168. }
  17169. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17170. {
  17171. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17172. {
  17173. check_ascii = value[0];
  17174. if( (check_ascii < 48) || (check_ascii > 57) )
  17175. {
  17176. isSuccess = ConfigurationStatus_Rejected;
  17177. }
  17178. else
  17179. {
  17180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17181. isSuccess = ConfigurationStatus_Accepted;
  17182. }
  17183. }
  17184. else
  17185. {
  17186. isSuccess = ConfigurationStatus_Rejected;
  17187. }
  17188. }
  17189. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17190. return isSuccess;
  17191. }
  17192. int TransactionMessageAttemptsGet(void)
  17193. {
  17194. return TransactionMessageAttemptsValue;
  17195. }
  17196. int FirstHeartBeatResponse(void)
  17197. {
  17198. return FirstHeartBeat;
  17199. }
  17200. int TransactionMessageRetryIntervalGet(void)
  17201. {
  17202. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17203. }
  17204. int ReadHttpStatus(int sock)
  17205. {
  17206. //char c;
  17207. char buff[1024]="",*ptr=buff+1;
  17208. int bytes_received, status;
  17209. DEBUG_INFO("Begin Response ..\n");
  17210. while((bytes_received = recv(sock, ptr, 1, 0))){
  17211. if(bytes_received==-1){
  17212. perror("ReadHttpStatus");
  17213. exit(1);
  17214. }
  17215. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17216. ptr++;
  17217. }
  17218. *ptr=0;
  17219. ptr=buff+1;
  17220. sscanf(ptr,"%*s %d ", &status);
  17221. DEBUG_INFO("%s\n",ptr);
  17222. DEBUG_INFO("status=%d\n",status);
  17223. DEBUG_INFO("End Response ..\n");
  17224. return (bytes_received>0)?status:0;
  17225. }
  17226. //the only filed that it parsed is 'Content-Length'
  17227. int ParseHeader(int sock)
  17228. {
  17229. //char c;
  17230. char buff[1024]="",*ptr=buff+4;
  17231. int bytes_received;
  17232. DEBUG_INFO("Begin HEADER ..\n");
  17233. while((bytes_received = recv(sock, ptr, 1, 0))){
  17234. if(bytes_received==-1){
  17235. perror("Parse Header");
  17236. exit(1);
  17237. }
  17238. if(
  17239. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17240. (ptr[-1]=='\r') && (*ptr=='\n' )
  17241. ) break;
  17242. ptr++;
  17243. }
  17244. *ptr=0;
  17245. ptr=buff+4;
  17246. //printf("%s",ptr);
  17247. if(bytes_received){
  17248. ptr=strstr(ptr,"Content-Length:");
  17249. if(ptr){
  17250. sscanf(ptr,"%*s %d",&bytes_received);
  17251. }else
  17252. bytes_received=-1; //unknown size
  17253. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17254. }
  17255. DEBUG_INFO("End HEADER ..\n");
  17256. return bytes_received ;
  17257. }
  17258. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17259. {
  17260. int result = TRUE;
  17261. char rmFileCmd[100]={0};
  17262. char FilePath[100]={0};
  17263. char ftpbuf[200];
  17264. int systemresult;
  17265. sprintf(FilePath,"/mnt/%s",filename);
  17266. system("ping 8.8.8.8 &");
  17267. if((access(FilePath,F_OK))!=-1)
  17268. {
  17269. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17270. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17271. system(rmFileCmd);
  17272. }
  17273. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17274. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17275. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17276. systemresult = system(ftpbuf);
  17277. if(systemresult != 0)
  17278. {
  17279. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17280. result = FALSE;
  17281. }
  17282. system("pkill ping");
  17283. return result;
  17284. }
  17285. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17286. {
  17287. int result = TRUE;
  17288. char rmFileCmd[100]={0};
  17289. char FilePath[100]={0};
  17290. char ftpbuf[200];
  17291. int systemresult;
  17292. sprintf(FilePath,"/mnt/%s",filename);
  17293. system("ping 8.8.8.8 &");
  17294. if((access(FilePath,F_OK))!=-1)
  17295. {
  17296. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17297. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17298. system(rmFileCmd);
  17299. }
  17300. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17301. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17302. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17303. systemresult = system(ftpbuf);
  17304. if(systemresult != 0)
  17305. {
  17306. DEBUG_WARN("scp error!\n");
  17307. result = FALSE;
  17308. }
  17309. system("pkill ping");
  17310. return result;
  17311. }
  17312. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17313. {
  17314. int result = TRUE;
  17315. char rmFileCmd[100]={0};
  17316. char FilePath[100]={0};
  17317. char ftpbuf[200];
  17318. int systemresult;
  17319. sprintf(FilePath,"/mnt/%s",filename);
  17320. system("ping 8.8.8.8 &");
  17321. if((access(FilePath,F_OK))!=-1)
  17322. {
  17323. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17324. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17325. system(rmFileCmd);
  17326. }
  17327. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17328. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17329. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17330. systemresult = system(ftpbuf);
  17331. if(systemresult != 0)
  17332. {
  17333. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17334. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17335. systemresult = system(ftpbuf);
  17336. if(systemresult != 0)
  17337. {
  17338. DEBUG_WARN("FTP download fail!\n");
  17339. result = FALSE;
  17340. }
  17341. }
  17342. system("pkill ping");
  17343. return result;
  17344. }
  17345. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17346. {
  17347. char rmFileCmd[100]={0};
  17348. char FilePath[100]={0};
  17349. char buf[512];
  17350. int systemresult = 0;
  17351. //DEBUG_INFO("filename=%s\n",filename);
  17352. //DEBUG_INFO("url=%s\n",url);
  17353. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17354. if((access(FilePath,F_OK))!=-1)
  17355. {
  17356. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17357. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17358. system(rmFileCmd);
  17359. }
  17360. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17361. if(fp == NULL)
  17362. {
  17363. DEBUG_INFO("log is NULL\n");
  17364. return FALSE;
  17365. }
  17366. else
  17367. {
  17368. fprintf(fp, "%s\n", url);
  17369. fprintf(fp, "%s\n", filename);
  17370. fclose(fp);
  17371. }
  17372. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17373. if(phpFP == NULL)
  17374. {
  17375. DEBUG_INFO("PHP upload fail.\n");
  17376. return FALSE;
  17377. }
  17378. else
  17379. {
  17380. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17381. {
  17382. if(strstr(buf, "result") != NULL)
  17383. {
  17384. sscanf(buf, "result: %d", &systemresult);
  17385. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17386. }
  17387. }
  17388. pclose(phpFP);
  17389. }
  17390. if(systemresult != 1)
  17391. {
  17392. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17393. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17394. if(phpFP == NULL)
  17395. {
  17396. DEBUG_WARN("PHP PUT upload fail.\n");
  17397. return FALSE;
  17398. }
  17399. else
  17400. {
  17401. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17402. {
  17403. if(strstr(buf, "result") != NULL)
  17404. {
  17405. sscanf(buf, "result: %d", &systemresult);
  17406. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17407. }
  17408. }
  17409. pclose(phpFP);
  17410. }
  17411. }
  17412. if(systemresult != 1)
  17413. {
  17414. DEBUG_WARN("PHP PUT upload fail.\n");
  17415. return FALSE;
  17416. }
  17417. return TRUE;
  17418. }
  17419. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17420. {
  17421. int result = FALSE;
  17422. char ftpbuf[200];
  17423. int systemresult;
  17424. /*
  17425. // Domaind name transfer to IP address
  17426. struct hostent* server;
  17427. char *IPbuffer;
  17428. server = gethostbyname(location);
  17429. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17430. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17431. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17432. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17433. systemresult = system(ftpbuf);
  17434. if(systemresult != 0)
  17435. {
  17436. DEBUG_INFO("ftpput error!\n");
  17437. }
  17438. else
  17439. {
  17440. result = TRUE;
  17441. DEBUG_INFO("ftpput OK!\n");
  17442. }
  17443. return result;
  17444. }
  17445. int GetOcppServerURL()
  17446. {
  17447. int result = FALSE;
  17448. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17449. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17450. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17451. struct yuarel url;
  17452. char urlStr[512];
  17453. // OCPPPH only
  17454. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17455. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17456. {
  17457. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17458. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17459. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17460. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17461. if(yuarel_parse(&url, urlStr) != -1)
  17462. {
  17463. sprintf(OcppProtocol, "%s", url.scheme);
  17464. sprintf(OcppHost, "%s", url.host);
  17465. if(url.path == NULL)
  17466. OcppTempPath[0] = '\0';
  17467. else
  17468. sprintf(OcppTempPath, "%s", url.path);
  17469. if(url.port == 0)
  17470. {
  17471. if(strcmp(OcppProtocol, "wss") == 0)
  17472. OcppPort = 443;
  17473. else
  17474. OcppPort = 80;
  17475. }
  17476. else
  17477. OcppPort = url.port;
  17478. result = TRUE;
  17479. }
  17480. }
  17481. else
  17482. {
  17483. strcpy(OcppHost,"");
  17484. }
  17485. return result;
  17486. }
  17487. int GetOcppPath()
  17488. {
  17489. int result = FALSE;
  17490. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17491. {
  17492. if(OcppTempPath == NULL)
  17493. {
  17494. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17495. }
  17496. else
  17497. {
  17498. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17499. }
  17500. result = TRUE;
  17501. goto End;
  17502. }
  17503. else
  17504. {
  17505. strcpy(OcppPath,"");
  17506. }
  17507. End:
  17508. return result;
  17509. }
  17510. int GetOcppPort()
  17511. {
  17512. return OcppPort;
  17513. }
  17514. int GetOcppConnStatus(void)
  17515. {
  17516. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17517. }
  17518. void SetOcppConnStatus(uint8_t status)
  17519. {
  17520. ShmOCPP16DataPH->OcppConnStatus = status;
  17521. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17522. }
  17523. int GetHeartBeatWithNOResponse(void)
  17524. {
  17525. return HeartBeatWithNOResponse;
  17526. }
  17527. void SetHeartBeatWithNOResponse(void)
  17528. {
  17529. HeartBeatWithNOResponse = 0;
  17530. }
  17531. void GetStartTransactionIdTag(int gun_index)
  17532. {
  17533. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17534. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17535. }
  17536. int GetStartTransactionId(int gun_index)
  17537. {
  17538. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17539. }
  17540. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17541. {
  17542. char ch;
  17543. FILE *fptr1;
  17544. int temptransactionId;
  17545. char str[100]={0};
  17546. temptransactionId = 0;
  17547. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17548. {
  17549. DEBUG_INFO("IdTag is empty.\n");
  17550. return temptransactionId;
  17551. }
  17552. /*------ Read the file ----------------*/
  17553. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17554. if (!fptr1)
  17555. {
  17556. DEBUG_INFO("QueueTransactionId file open error.\n");
  17557. //printf(" File not found or unable to open the input file!!\n");
  17558. return temptransactionId;
  17559. }
  17560. ch=fgetc(fptr1);
  17561. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17562. rewind(fptr1);
  17563. if(ch!=EOF)
  17564. {
  17565. // printf("%c",ch);
  17566. while (fgets(str, 100, fptr1) != NULL)
  17567. {
  17568. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17569. if(str[0]=='\0')
  17570. {
  17571. break;
  17572. }
  17573. char *revbuf[8] = {0}; // Variable store string split
  17574. int num = 0;// Quantity after string split
  17575. DEBUG_INFO("Transaction queue data= %s\n", str);
  17576. splitstring(str,",",revbuf,&num); // String split
  17577. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17578. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17579. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17580. DEBUG_INFO("------------------------------\n");
  17581. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17582. {
  17583. if(isStopTransaction)
  17584. {
  17585. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17586. {
  17587. temptransactionId = atoi(revbuf[2]);
  17588. //break;
  17589. }
  17590. }
  17591. else
  17592. {
  17593. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17594. {
  17595. temptransactionId = atoi(revbuf[2]);
  17596. //break;
  17597. }
  17598. }
  17599. }
  17600. }
  17601. }
  17602. else
  17603. DEBUG_INFO("EOF\n");
  17604. fclose(fptr1);
  17605. /*------- End of reading ---------------*/
  17606. return temptransactionId;
  17607. }
  17608. void SetTransactionIdZero(int transactionId)
  17609. {
  17610. char ch;
  17611. FILE *fptr1, *fptr2;
  17612. int temptransactionId = 0;
  17613. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17614. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17615. if (!fptr1)
  17616. {
  17617. //printf(" File not found or unable to open the input file!!\n");
  17618. return ;
  17619. }
  17620. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17621. if (!fptr2)
  17622. {
  17623. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17624. fclose(fptr1);
  17625. return ;
  17626. }
  17627. ch=fgetc(fptr1);
  17628. rewind(fptr1);
  17629. if(ch!=EOF)
  17630. {
  17631. // copy all contents to the temporary file except the specific line
  17632. while (fgets(str, 100, fptr1) != NULL)
  17633. {
  17634. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17635. if(str[0]=='\0')
  17636. {
  17637. break;
  17638. }
  17639. char *revbuf[8] = {0};
  17640. int num = 0;
  17641. strcpy(strtemp, str);
  17642. splitstring(str,",",revbuf,&num);
  17643. if(revbuf[2][0] != '\0')
  17644. {
  17645. temptransactionId = atoi(revbuf[2]);
  17646. if(transactionId != temptransactionId)
  17647. {
  17648. fprintf(fptr2, "%s\n", strtemp);
  17649. }
  17650. }
  17651. }
  17652. }
  17653. fclose(fptr1);
  17654. fclose(fptr2);
  17655. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17656. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17657. /*------ Read the file ----------------*/
  17658. }
  17659. int InternetDisconnect(void)
  17660. {
  17661. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17662. }
  17663. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17664. void storeTempStopTransaction(int gun_index)
  17665. {
  17666. char guid[37]={0};
  17667. int tempIndex = 0;
  17668. char TempStopTransaction[256];
  17669. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17670. DEBUG_INFO("storeTempStopTransaction...\n");
  17671. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17672. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17673. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17674. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17676. {
  17677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17678. {
  17679. tempIndex = ((gun_index==2) ? 1: 0);
  17680. }
  17681. else
  17682. {
  17683. tempIndex = gun_index;
  17684. }
  17685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17686. {
  17687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17688. {
  17689. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17690. }
  17691. }// END OF CHAdeMO_QUANTITY
  17692. }
  17693. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17694. {
  17695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17696. {
  17697. tempIndex = ((gun_index==2) ? 1: 0);
  17698. }
  17699. else
  17700. {
  17701. tempIndex = gun_index;
  17702. }
  17703. for (int index = 0; index < CCS_QUANTITY; index++)
  17704. {
  17705. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17706. {
  17707. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17708. }
  17709. }// END OF CCS_QUANTITY
  17710. }
  17711. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17712. {
  17713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17714. {
  17715. tempIndex = ((gun_index==2) ? 1: 0);
  17716. }
  17717. else
  17718. {
  17719. tempIndex = gun_index;
  17720. }
  17721. for (int index = 0; index < GB_QUANTITY; index++)
  17722. {
  17723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17724. {
  17725. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17726. }
  17727. }// END OF GB_QUANTITY
  17728. }
  17729. else if(gunType[gun_index] == GUN_TYPE_DO)
  17730. {
  17731. tempIndex = gun_index;
  17732. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17733. {
  17734. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17735. {
  17736. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17737. }
  17738. }
  17739. }
  17740. else
  17741. {
  17742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17743. {
  17744. tempIndex = 2;
  17745. }
  17746. else
  17747. {
  17748. tempIndex = gun_index;
  17749. }
  17750. for (int index = 0; index < AC_QUANTITY; index++)
  17751. {
  17752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17753. {
  17754. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17755. }
  17756. }// END OF AC_QUANTITY
  17757. }
  17758. //Stop Transaction Time
  17759. struct timeval tmnow;
  17760. struct tm *tm;
  17761. char buf[28];//, usec_buf[6];
  17762. gettimeofday(&tmnow, NULL);
  17763. time_t t;
  17764. t = time(NULL);
  17765. /*UTC time and date*/
  17766. tm = gmtime(&t);
  17767. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17769. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17770. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17771. random_uuid(guid);
  17772. /***********************************transactionData******************************************************/
  17773. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17775. //=================================
  17776. //1. Transaction_Begin
  17777. //=================================
  17778. //============================== Energy.Active.Import.Interval ===========================================
  17779. //=================================
  17780. //2. Transaction_End
  17781. //=================================
  17782. //2.1====================================== Current.Import L1 ==============================================
  17783. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17784. {
  17785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17787. {
  17788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17789. {
  17790. tempIndex = ((gun_index==2) ? 1: 0);
  17791. }
  17792. else
  17793. {
  17794. tempIndex = gun_index;
  17795. }
  17796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17797. {
  17798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17799. {
  17800. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17801. }
  17802. }// End of for CHAdeMO_QUANTITY
  17803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17804. }
  17805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17808. {
  17809. tempIndex = ((gun_index==2) ? 1: 0);
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < CCS_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17818. {
  17819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17820. }
  17821. }// End of for CCS_QUANTITY
  17822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17823. }
  17824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17825. {
  17826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17827. {
  17828. tempIndex = ((gun_index==2) ? 1: 0);
  17829. }
  17830. else
  17831. {
  17832. tempIndex = gun_index;
  17833. }
  17834. for (int index = 0; index < GB_QUANTITY; index++)
  17835. {
  17836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17837. {
  17838. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17839. }
  17840. }// End of for GB_QUANTITY
  17841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17842. }
  17843. else if(gunType[gun_index] == GUN_TYPE_DO)
  17844. {
  17845. tempIndex = gun_index;
  17846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17847. {
  17848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17849. {
  17850. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17851. }
  17852. }
  17853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17854. }
  17855. else
  17856. {
  17857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17858. {
  17859. tempIndex = 2;
  17860. }
  17861. else
  17862. {
  17863. tempIndex = gun_index;
  17864. }
  17865. for (int index = 0; index < AC_QUANTITY; index++)
  17866. {
  17867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17868. {
  17869. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17870. }
  17871. }// End of for AC_QUANTITY
  17872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17873. }
  17874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17875. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17877. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17880. }
  17881. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17882. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17883. {
  17884. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17885. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17886. {
  17887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17888. {
  17889. tempIndex = ((gun_index==2) ? 1: 0);
  17890. }
  17891. else
  17892. {
  17893. tempIndex = gun_index;
  17894. }
  17895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17896. {
  17897. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17898. {
  17899. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17900. }
  17901. }// END OF CHAdeMO_QUANTITY
  17902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17903. }
  17904. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17907. {
  17908. tempIndex = ((gun_index==2) ? 1: 0);
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < CCS_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17917. {
  17918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17919. }
  17920. }// END OF CCS_QUANTITY
  17921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17922. }
  17923. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17924. {
  17925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17926. {
  17927. tempIndex = ((gun_index==2) ? 1: 0);
  17928. }
  17929. else
  17930. {
  17931. tempIndex = gun_index;
  17932. }
  17933. for (int index = 0; index < GB_QUANTITY; index++)
  17934. {
  17935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17936. {
  17937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17938. }
  17939. }// END OF GB_QUANTITY
  17940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17941. }
  17942. else if(gunType[gun_index] == GUN_TYPE_DO)
  17943. {
  17944. tempIndex = gun_index;
  17945. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17946. {
  17947. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17948. {
  17949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17950. }
  17951. }
  17952. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17953. }
  17954. else
  17955. {
  17956. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17957. {
  17958. tempIndex = 2;
  17959. }
  17960. else
  17961. {
  17962. tempIndex = gun_index;
  17963. }
  17964. for (int index = 0; index < AC_QUANTITY; index++)
  17965. {
  17966. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17967. {
  17968. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17969. }
  17970. }// END OF AC_QUANTITY
  17971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17972. }
  17973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17976. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17979. }
  17980. //2.3====================================== Power.Active.Import =========================================
  17981. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17982. {
  17983. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17984. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17985. {
  17986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17987. {
  17988. tempIndex = ((gun_index==2) ? 1: 0);
  17989. }
  17990. else
  17991. {
  17992. tempIndex = gun_index;
  17993. }
  17994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17995. {
  17996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17997. {
  17998. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17999. }
  18000. } // End for CHAdeMO_QUANTITY
  18001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18002. }
  18003. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18004. {
  18005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18006. {
  18007. tempIndex = ((gun_index==2) ? 1: 0);
  18008. }
  18009. else
  18010. {
  18011. tempIndex = gun_index;
  18012. }
  18013. for (int index = 0; index < CCS_QUANTITY; index++)
  18014. {
  18015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18016. {
  18017. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18018. }
  18019. } // END for CCS_QUANTITY
  18020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18021. }
  18022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18023. {
  18024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18025. {
  18026. tempIndex = ((gun_index==2) ? 1: 0);
  18027. }
  18028. else
  18029. {
  18030. tempIndex = gun_index;
  18031. }
  18032. for (int index = 0; index < GB_QUANTITY; index++)
  18033. {
  18034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18035. {
  18036. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18037. }
  18038. }// END for GB_QUANTITY
  18039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18040. }
  18041. else if(gunType[gun_index] == GUN_TYPE_DO)
  18042. {
  18043. tempIndex = gun_index;
  18044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18045. {
  18046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18047. {
  18048. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18049. }
  18050. }
  18051. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18052. }
  18053. else
  18054. {
  18055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18056. {
  18057. tempIndex = 2;
  18058. }
  18059. else
  18060. {
  18061. tempIndex = gun_index;
  18062. }
  18063. for (int index = 0; index < AC_QUANTITY; index++)
  18064. {
  18065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18066. {
  18067. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18068. }
  18069. } // END for AC_QUANTITY
  18070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18071. }
  18072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18075. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18078. }
  18079. //2.4====================================== Voltage L1 ====================================================
  18080. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18081. {
  18082. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18083. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18084. {
  18085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18086. {
  18087. tempIndex = ((gun_index==2) ? 1: 0);
  18088. }
  18089. else
  18090. {
  18091. tempIndex = gun_index;
  18092. }
  18093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18094. {
  18095. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18096. {
  18097. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18098. }
  18099. } // END OF FOR CHAdeMO_QUANTITY
  18100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18101. }
  18102. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18103. {
  18104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18105. {
  18106. tempIndex = ((gun_index==2) ? 1: 0);
  18107. }
  18108. else
  18109. {
  18110. tempIndex = gun_index;
  18111. }
  18112. for (int index = 0; index < CCS_QUANTITY; index++)
  18113. {
  18114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18115. {
  18116. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18117. }
  18118. } // END OF FOR CCS_QUANTITY
  18119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18120. }
  18121. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18122. {
  18123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18124. {
  18125. tempIndex = ((gun_index==2) ? 1: 0);
  18126. }
  18127. else
  18128. {
  18129. tempIndex = gun_index;
  18130. }
  18131. for (int index = 0; index < GB_QUANTITY; index++)
  18132. {
  18133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18134. {
  18135. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18136. }
  18137. } // END OF FOR GB_QUANTITY
  18138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18139. }
  18140. else if(gunType[gun_index] == GUN_TYPE_DO)
  18141. {
  18142. tempIndex = gun_index;
  18143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18144. {
  18145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18146. {
  18147. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18148. }
  18149. }
  18150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18151. }
  18152. else
  18153. {
  18154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18155. {
  18156. tempIndex = 2;
  18157. }
  18158. else
  18159. {
  18160. tempIndex = gun_index;
  18161. }
  18162. for (int index = 0; index < AC_QUANTITY; index++)
  18163. {
  18164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18165. {
  18166. 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
  18167. }
  18168. } // END OF FOR AC_QUANTITY
  18169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18170. }
  18171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18174. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18177. }
  18178. //2.5============================================== End SoC =========================================================
  18179. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18180. {
  18181. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18182. 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))
  18183. {
  18184. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18185. {
  18186. tempIndex = ((gun_index==2) ? 1: 0);
  18187. }
  18188. else
  18189. {
  18190. tempIndex = gun_index;
  18191. }
  18192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18193. {
  18194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18195. {
  18196. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18197. {
  18198. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18199. }
  18200. }
  18201. }
  18202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18203. {
  18204. for (int index = 0; index < CCS_QUANTITY; index++)
  18205. {
  18206. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18207. {
  18208. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18209. }
  18210. }
  18211. }
  18212. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18213. {
  18214. for (int index = 0; index < GB_QUANTITY; index++)
  18215. {
  18216. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18217. {
  18218. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18219. }
  18220. }
  18221. }
  18222. else if(gunType[gun_index] == GUN_TYPE_DO)
  18223. {
  18224. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18225. {
  18226. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18227. {
  18228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18229. }
  18230. }
  18231. }
  18232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18234. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18238. } // END FOR DC CASE
  18239. }
  18240. //2.6====================================== Current.Import L2 ==============================================
  18241. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18242. {
  18243. // AC 3 phase L2 current
  18244. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18245. {
  18246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18247. {
  18248. tempIndex = 2;
  18249. }
  18250. else
  18251. {
  18252. tempIndex = gun_index;
  18253. }
  18254. for (int index = 0; index < AC_QUANTITY; index++)
  18255. {
  18256. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18257. {
  18258. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18259. }
  18260. }// End of for AC_QUANTITY
  18261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18262. }
  18263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18268. }
  18269. //2.7====================================== Current.Import L3 ==============================================
  18270. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18271. {
  18272. // AC 3 phase L3 current
  18273. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18274. {
  18275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18276. {
  18277. tempIndex = 2;
  18278. }
  18279. else
  18280. {
  18281. tempIndex = gun_index;
  18282. }
  18283. for (int index = 0; index < AC_QUANTITY; index++)
  18284. {
  18285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18286. {
  18287. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18288. }
  18289. }// End of for AC_QUANTITY
  18290. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18291. }
  18292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18294. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18295. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18297. }
  18298. //2.9====================================== Voltage L2 ====================================================
  18299. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18300. {
  18301. // AC 3 phase L2 volatge
  18302. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18303. {
  18304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18305. {
  18306. tempIndex = 2;
  18307. }
  18308. else
  18309. {
  18310. tempIndex = gun_index;
  18311. }
  18312. for (int index = 0; index < AC_QUANTITY; index++)
  18313. {
  18314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18315. {
  18316. 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
  18317. }
  18318. } // END OF FOR AC_QUANTITY
  18319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18320. }
  18321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18322. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18323. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18324. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18325. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18326. }
  18327. //2.10====================================== Voltage L3 ====================================================
  18328. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18329. {
  18330. // AC 3 phase L3 volatge
  18331. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18332. {
  18333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18334. {
  18335. tempIndex = 2;
  18336. }
  18337. else
  18338. {
  18339. tempIndex = gun_index;
  18340. }
  18341. for (int index = 0; index < AC_QUANTITY; index++)
  18342. {
  18343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18344. {
  18345. 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
  18346. }
  18347. } // END OF FOR AC_QUANTITY
  18348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18349. }
  18350. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18351. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18353. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18354. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18355. }
  18356. //====================== Start SoC ================================
  18357. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18358. {
  18359. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18360. 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))
  18361. {
  18362. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18363. {
  18364. tempIndex = ((gun_index==2) ? 1: 0);
  18365. }
  18366. else
  18367. {
  18368. tempIndex = gun_index;
  18369. }
  18370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18371. {
  18372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18373. {
  18374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18375. {
  18376. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18377. }
  18378. }
  18379. }
  18380. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18381. {
  18382. for (int index = 0; index < CCS_QUANTITY; index++)
  18383. {
  18384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18385. {
  18386. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18387. }
  18388. }
  18389. }
  18390. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18391. {
  18392. for (int index = 0; index < GB_QUANTITY; index++)
  18393. {
  18394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18395. {
  18396. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18397. }
  18398. }
  18399. }
  18400. else if(gunType[gun_index] == GUN_TYPE_DO)
  18401. {
  18402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18403. {
  18404. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18405. {
  18406. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18407. }
  18408. }
  18409. }
  18410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18413. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18416. } // END FOR DC CASE
  18417. }
  18418. //======================================== Message create ==============================================
  18419. json_object *StopTransaction = json_object_new_object();
  18420. json_object *transactionDatas = json_object_new_array();
  18421. json_object *sampledValues = json_object_new_array();
  18422. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18423. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18424. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18425. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18426. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18427. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18428. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18429. {
  18430. json_object *transactionData = json_object_new_object();
  18431. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18432. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18433. {
  18434. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18435. {
  18436. json_object *sampledValue = json_object_new_object();
  18437. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18438. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18439. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18440. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18441. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18442. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18443. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18444. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18445. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18446. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18447. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18448. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18449. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18450. json_object_array_add(sampledValues, sampledValue);
  18451. }
  18452. }
  18453. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18454. json_object_array_add(transactionDatas, transactionData);
  18455. }
  18456. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18457. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18458. ,MESSAGE_TYPE_CALL
  18459. ,guid
  18460. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18461. json_object_put(StopTransaction);
  18462. // Check File "TempStopTransaction" Exist
  18463. if((access(TempStopTransaction,F_OK))!=-1)
  18464. {
  18465. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18466. fclose(fopen(TempStopTransaction, "w"));
  18467. }
  18468. else
  18469. {
  18470. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18471. FILE *log = fopen(TempStopTransaction, "w+");
  18472. if(log == NULL)
  18473. {
  18474. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18475. return ;
  18476. }
  18477. else
  18478. {
  18479. fclose(log);
  18480. }
  18481. }
  18482. //Add TempStopTransaction | Update TempStopTransaction
  18483. // open file for writing
  18484. FILE *outfile;
  18485. outfile = fopen (TempStopTransaction, "a");
  18486. //DEBUG_INFO("data = %s\n", queuedata);
  18487. fputs(queuedata, outfile);
  18488. fputs("\n", outfile);
  18489. fclose (outfile);
  18490. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18491. }
  18492. void checkTempStopTransaction(int gun_index)
  18493. {
  18494. FILE *fptr1;
  18495. char ch;
  18496. char str[QUEUE_MESSAGE_LENGTH]={0};
  18497. char guid[37]={0};
  18498. char tempdata[65]={0};
  18499. char connectorStr[2]={0};
  18500. char TempStopTransaction[256];
  18501. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18502. fptr1 = fopen(TempStopTransaction, "r");
  18503. //TempStopTransaction格式: 槍號,StopTransaction封包
  18504. if (!fptr1)
  18505. {
  18506. //printf(" File not found or unable to open the input file!!\n");
  18507. return ;
  18508. }
  18509. ch=fgetc(fptr1);
  18510. //printf(" Now the content of the file %s is : \n",fname);
  18511. rewind(fptr1);
  18512. if(ch!=EOF)
  18513. {
  18514. // copy all contents to the temporary file except the specific line
  18515. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18516. {
  18517. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18518. if(str[0]=='\0')
  18519. {
  18520. break;
  18521. }
  18522. //TempStopTransaction格式: 槍號,StopTransaction封包
  18523. strncpy(connectorStr, str, 1);
  18524. if(atoi(connectorStr) != (gun_index+1))
  18525. {
  18526. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18527. fclose(fptr1);
  18528. return ;
  18529. }
  18530. //random_uuid(guid);
  18531. strncpy(guid, str+6, 36); //copy guid
  18532. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18533. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18534. {
  18535. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18536. }
  18537. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18538. OCPP_insert_transaction_msg(NO, str);
  18539. memset(str,0,ARRAY_SIZE(str));
  18540. }
  18541. }
  18542. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18543. fclose(fptr1);
  18544. remove(TempStopTransaction); // remove the original file
  18545. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18546. }
  18547. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18548. {
  18549. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18550. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18551. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18552. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18553. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18554. }
  18555. int GetWebSocketPingInterval(void)
  18556. {
  18557. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18558. }
  18559. int GetServerSign(void)
  18560. {
  18561. return server_sign;
  18562. }
  18563. uint8_t GetOcppSecurityProfile()
  18564. {
  18565. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18566. }
  18567. void GetOcppChargerBoxId(uint8_t *data)
  18568. {
  18569. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18570. }
  18571. void GetOcppSecurityPassword(uint8_t *data)
  18572. {
  18573. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18574. }
  18575. void SetOcppVersion(uint8_t *version)
  18576. {
  18577. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18578. DEBUG_INFO("ocpp version: %s\n", version);
  18579. if(strstr((char*)version, "ocpp1.6") != NULL)
  18580. {
  18581. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18582. }
  18583. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18584. {
  18585. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18586. system("pkill OcppBackend");
  18587. }
  18588. }
  18589. void SetServerSign(int value)
  18590. {
  18591. server_sign = value;
  18592. }
  18593. int GetBootNotificationInterval(void)
  18594. {
  18595. return BootNotificationInterval;
  18596. }
  18597. int GetInternetConn(void)
  18598. {
  18599. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18600. }
  18601. int GetBackendConnectionTimeout(void)
  18602. {
  18603. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18604. }
  18605. int isConnectorInitMode(int gun_index)
  18606. {
  18607. int tempIndex = 0;
  18608. int result = TRUE;
  18609. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18610. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18611. {
  18612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18613. {
  18614. tempIndex = ((gun_index==2) ? 1: 0);
  18615. }
  18616. else
  18617. {
  18618. tempIndex = gun_index;
  18619. }
  18620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18621. {
  18622. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18623. {
  18624. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18625. } //end of the same index
  18626. }//end of for CHAdeMO_QUANTITY
  18627. }
  18628. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18629. {
  18630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18631. {
  18632. tempIndex = ((gun_index==2) ? 1: 0);
  18633. }
  18634. else
  18635. {
  18636. tempIndex = gun_index;
  18637. }
  18638. for (int index = 0; index < CCS_QUANTITY; index++)
  18639. {
  18640. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18641. {
  18642. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18643. } //end of the same index
  18644. } // end of for CCS_QUANTITY
  18645. }
  18646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18647. {
  18648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18649. {
  18650. tempIndex = ((gun_index==2) ? 1: 0);
  18651. }
  18652. else
  18653. {
  18654. tempIndex = gun_index;
  18655. }
  18656. for (int index = 0; index < GB_QUANTITY; index++)
  18657. {
  18658. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18659. {
  18660. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18661. } //end of the same index
  18662. } // end of for GB_QUANTITY
  18663. }
  18664. else if(gunType[gun_index] == GUN_TYPE_DO)
  18665. {
  18666. tempIndex = gun_index;
  18667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18668. {
  18669. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18670. {
  18671. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18672. } //end of the same index
  18673. }
  18674. }
  18675. else
  18676. {
  18677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18678. {
  18679. tempIndex = 2;
  18680. }
  18681. else
  18682. {
  18683. tempIndex = gun_index;
  18684. }
  18685. for (int index = 0; index < AC_QUANTITY; index++)
  18686. {
  18687. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18688. {
  18689. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18690. }//end of the same index
  18691. }//end of for AC_QUANTITY
  18692. }
  18693. return result;
  18694. }
  18695. void refreshProcDogTimer()
  18696. {
  18697. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18698. }
  18699. void InitialSystemValue(void)
  18700. {
  18701. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18702. locallistVersion=0;
  18703. BootNotificationInterval = 0;
  18704. authorizeRetryTimes = 0;
  18705. GunStatusInterval = 10;
  18706. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18707. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18708. //Hear Beat
  18709. HeartBeatWithNOResponse = 0;
  18710. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18711. FirstHeartBeat = 0;
  18712. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18713. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18714. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18715. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18716. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18717. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18718. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18719. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18720. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18721. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18722. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18723. //Status && ConnectorPlugIn Setting
  18724. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18725. {
  18726. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18727. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18728. }
  18729. for (int index = 0; index < CCS_QUANTITY; index++)
  18730. {
  18731. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18732. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18733. }
  18734. for (int index = 0; index < GB_QUANTITY; index++)
  18735. {
  18736. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18737. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18738. }
  18739. for (int index = 0; index < AC_QUANTITY; index++)
  18740. {
  18741. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18742. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18743. }
  18744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18745. {
  18746. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18747. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18748. }
  18749. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18750. {
  18751. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18752. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18753. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18754. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18755. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18756. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18757. }
  18758. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18759. refreshStartTimer(&clientTime.Heartbeat);
  18760. sleep(1);
  18761. }
  18762. void LWS_Send(char *str)
  18763. {
  18764. //=====================================================
  18765. // Check InternetConn 0: disconnected, 1: connected
  18766. //====================================================
  18767. if(GetOcppConnStatus() == 0)
  18768. {
  18769. DEBUG_INFO("offline now !!!\n");
  18770. return;
  18771. }
  18772. // Only disable isWebsocketSendable operation initiated by charger
  18773. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18774. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18775. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18776. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18777. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18778. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18779. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18780. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18781. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18782. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18783. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18784. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18785. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18786. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18787. {
  18788. isWebsocketSendable = 0;
  18789. }
  18790. pthread_mutex_lock(&lock_send);
  18791. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18792. sprintf((char *)SendBuffer, "%s", str);
  18793. SendBufLen = strlen(str);
  18794. pthread_mutex_unlock(&lock_send);
  18795. lws_callback_on_writable(wsi_client);
  18796. //lws_service(context, 0);
  18797. //sleep(1);
  18798. }
  18799. void LWS_SendNow(char *str)
  18800. {
  18801. //=====================================================
  18802. // Check InternetConn 0: disconnected, 1: connected
  18803. //====================================================
  18804. if(GetOcppConnStatus() == 0)
  18805. {
  18806. DEBUG_INFO("offline now !!!\n");
  18807. return;
  18808. }
  18809. // Only disable isWebsocketSendable operation initiated by charger
  18810. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18811. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18812. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18813. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18814. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18815. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18816. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18817. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18818. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18819. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18820. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18821. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18822. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18823. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18824. {
  18825. isWebsocketSendable = 0;
  18826. }
  18827. pthread_mutex_lock(&lock_send);
  18828. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18829. sprintf((char *)SendBuffer, "%s", str);
  18830. SendBufLen = strlen(str);
  18831. pthread_mutex_unlock(&lock_send);
  18832. lws_callback_on_writable(wsi_client);
  18833. lws_service(context, 0);
  18834. //sleep(1);
  18835. }